0% found this document useful (0 votes)
3 views

git

This Git Cheat Sheet provides essential commands for Git configuration, repository management, and basic workflows, including branching, merging, and working with remote repositories. It also covers undoing changes, stashing, tagging, viewing differences, cherry-picking, and using rebase and squash. Additionally, it includes shortcuts for Git log and productivity aliases to streamline Git usage.

Uploaded by

mini10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

git

This Git Cheat Sheet provides essential commands for Git configuration, repository management, and basic workflows, including branching, merging, and working with remote repositories. It also covers undoing changes, stashing, tagging, viewing differences, cherry-picking, and using rebase and squash. Additionally, it includes shortcuts for Git log and productivity aliases to streamline Git usage.

Uploaded by

mini10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Git Cheat Sheet 📝🚀

1. Git Configuration

git config --global user.name "Your Name"

git config --global user.email "[email protected]"

git config --global core.editor "vim"

git config --global init.defaultBranch main

git config --list # View all global settings

2. Creating & Cloning Repositories

git init # Initialize a new Git repository

git clone <repo_url> # Clone an existing repository

3. Basic Workflow

git status # Check the status of your working directory

git add <file> # Stage a file for commit

git add . # Stage all changes

git commit -m "Commit message" # Commit staged changes

git commit -am "Commit message" # Add & commit tracked files
in one step

git log # Show commit history

4. Branching & Merging

git branch # List branches

git branch <branch_name> # Create a new branch

git checkout <branch_name> # Switch to a branch

git checkout -b <branch_name> # Create and switch to a new


branch

git merge <branch_name> # Merge a branch into the current


branch

git branch -d <branch_name> # Delete a branch


git branch -D <branch_name> # Force delete a branch

5. Working with Remote Repositories

git remote -v # View remote repositories

git remote add origin <url> # Add a remote repository

git push -u origin main # Push to a remote repository (first


time)

git push # Push changes to the remote repo

git fetch # Fetch latest changes from remote

git pull # Pull latest changes from remote

6. Undoing Changes

git checkout -- <file> # Discard changes in working directory

git reset HEAD <file> # Unstage a file

git reset --soft HEAD~1 # Undo last commit but keep changes
staged

git reset --hard HEAD~1 # Undo last commit and discard


changes

git revert <commit_id> # Create a new commit to undo a


previous commit

7. Stashing Changes

git stash # Stash changes

git stash list # List stashes

git stash apply # Reapply the latest stash

git stash drop # Delete latest stash

git stash pop # Apply and remove the latest stash

8. Tagging

git tag # List all tags


git tag -a v1.0 -m "Version 1.0" # Create an annotated tag

git push origin --tags # Push tags to remote

git checkout v1.0 # Switch to a tag

9. Viewing Differences

git diff # Show changes in working directory

git diff --staged # Show changes staged for commit

git diff <branch1>..<branch2> # Compare branches

10. Cherry Picking

git cherry-pick <commit_id> # Apply a commit from another


branch

11. Git Rebase & Squash

git rebase <branch> # Reapply commits on top of another


branch

git rebase -i HEAD~3 # Interactive rebase (squash commits)

12. Deleting Remote Branch

git push origin --delete <branch> # Delete remote branch

13. Reset vs. Revert vs. Checkout

Command Effect

Moves branch pointer, can discard


git reset
commits

Creates a new commit that undoes


git revert
previous changes

git
Switches branches or restores files
checkout
14. Git Log Shortcuts

git log --oneline --graph --decorate --all # Pretty log view

15. Aliases for Productivity

git config --global alias.st "status"

git config --global alias.co "checkout"

git config --global alias.br "branch"

git config --global alias.cm "commit -m"

git config --global alias.hist "log --oneline --graph --decorate --all"

Need help automating Git workflows in CI/CD? 🚀 Let me know! 😊

You might also like