Cheat Sheet
Git Cheat Sheet
The most-used Git commands grouped by task.
Setup
git config --global user.name "Name" | Set committer name |
git config --global user.email you@example.com | Set committer email |
git init | Initialize a new repository |
git clone <url> | Clone a remote repository |
Daily Workflow
git status | Show changes |
git add <file> / git add . | Stage files |
git commit -m "message" | Commit staged changes |
git commit -am "message" | Stage tracked + commit |
git push / git pull | Push or pull current branch |
git fetch --all --prune | Fetch and prune deleted remote branches |
Branches
git branch | List branches |
git switch -c <name> | Create + switch to a new branch |
git switch <name> | Switch to a branch |
git merge <branch> | Merge into current |
git rebase <branch> | Rebase current onto branch |
git branch -d <name> | Delete a merged branch |
History & Inspection
git log --oneline --graph --decorate --all | Compact graph of all branches |
git diff / git diff --staged | Unstaged / staged changes |
git show <commit> | Show a commit |
git blame <file> | Who changed each line |
Undoing
git restore <file> | Discard working changes |
git restore --staged <file> | Unstage a file |
git commit --amend | Amend last commit |
git revert <commit> | Reverse a commit safely |
git reset --hard <commit> | Discard all changes back to a commit |
Stash
git stash push -m "msg" | Save working changes |
git stash list | List stashes |
git stash pop | Re-apply most recent + drop |
Tags & Remotes
git tag v1.2.3 | Create a lightweight tag |
git tag -a v1.2.3 -m "msg" | Annotated tag |
git push --tags | Push tags |
git remote -v | List remotes |
git remote add origin <url> | Add a remote |