Git Cheatsheet
Git is the backbone of modern version control. This cheatsheet organizes 25+ essential Git commands by workflow scenario — from your first commit to advanced branch surgery. Every command includes a practical example so you can use it immediately.
Updated: 2026-07-15·26 commands
Quick Reference by Task
| What you want to do | Command |
| Start a new project | git init / git clone |
| Save your work | git add → git commit |
| See what changed | git status / git diff / git log |
| Create a branch | git checkout -b / git switch -c |
| Merge branches | git merge / git rebase |
| Undo a mistake | git revert / git reset |
| Pause your work | git stash |
| Sync with remote | git push / git pull |
Setup(2)
| Command | Level | ||
|---|---|---|---|
git initInitialize a new Git repository | Basic | git init my-project | |
git cloneClone a remote repository locally | Basic | git clone https://github.com/user/repo.git |
Basic(5)
| Command | Level | ||
|---|---|---|---|
git addStage changes for commit | Basic | git add src/ 或 git add -A | |
git commitCommit staged changes | Basic | git commit -m "feat: add login feature" | |
git statusShow working tree status | Basic | git status | |
git diffShow changes between commits/working tree | Basic | git diff 或 git diff --staged | |
git logShow commit logs | Basic | git log --oneline --graph --all |
Branch(5)
| Command | Level | ||
|---|---|---|---|
git branchList, create, or delete branches | Basic | git branch feature/login | |
git checkout -bCreate and switch to a new branch | Basic | git checkout -b feature/login | |
git switchSwitch to an existing branch (modern way) | Intermediate | git switch feature/login | |
git mergeMerge a branch into the current branch If conflicts occur, resolve then git add + git commit | Intermediate | git merge feature/login | |
git rebaseReapply commits on top of another base Never rebase branches that have been pushed | Expert | git rebase main |
Stash(3)
| Command | Level | ||
|---|---|---|---|
git stashTemporarily save working directory changes | Intermediate | git stash | |
git stash popRestore and remove the last stash | Intermediate | git stash pop | |
git stash listList all stashed changes | Intermediate | git stash list |
Undo(4)
| Command | Level | ||
|---|---|---|---|
git reset --soft HEAD~1Undo last commit, keep changes staged If already pushed, use git revert instead | Intermediate | git reset --soft HEAD~1 | |
git reset --hard HEAD~1Undo last commit, discard all changes (dangerous) 🔴 Irreversible! Discarded changes cannot be recovered | Expert | git reset --hard HEAD~1 | |
git revertCreate a new commit that undoes a previous commit | Intermediate | git revert abc1234 | |
git restoreDiscard uncommitted changes in working tree | Basic | git restore src/app.ts 或 git restore . |
Remote(4)
| Command | Level | ||
|---|---|---|---|
git pushPush local commits to remote | Basic | git push origin main | |
git pullFetch and merge from remote | Basic | git pull origin main | |
git fetchFetch latest data from remote (no auto-merge) | Intermediate | git fetch origin | |
git remote -vShow remote repositories | Basic | git remote -v |
Advanced(3)
| Command | Level | ||
|---|---|---|---|
git tagList or create tags | Intermediate | git tag v1.0.0 | |
git cherry-pickApply a specific commit to the current branch | Expert | git cherry-pick abc1234 | |
git bisectBinary search to find the commit that introduced a bug | Expert | git bisect start HEAD v1.0 |
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-15.