All cheatsheets
Git · Cheatsheet
Git Cheatsheet — Daily Commands + Rescue Operations
Everyday git, plus the rescue commands you'll Google at 2 AM: reflog, cherry-pick, interactive rebase, and how to un-break a force-push.
Updated 2026-05-21 9 min
Setup & config
| git config --global user.name 'You' | Set author name |
| git config --global user.email 'you@x.com' | Set author email |
| git config --global init.defaultBranch main | Default branch = main |
| git config --global pull.rebase true | Rebase on pull (no merge bubbles) |
| git config --global core.autocrlf input | Linux line endings on commit |
| git config --global alias.lg 'log --oneline --graph --all' | Pretty log alias |
Branching
| git switch -c feature/x | Create + checkout branch |
| git branch -a | List all branches (local + remote) |
| git branch -d feature/x | Delete merged branch |
| git branch -D feature/x | Force delete |
| git push origin --delete feature/x | Delete remote branch |
| git fetch -p | Fetch + prune stale remote refs |
Committing
| git add -p | Stage hunks interactively (review every change) |
| git commit -m 'feat: x' -m 'body' | Subject + body in one line |
| git commit --amend --no-edit | Add staged files to last commit |
| git commit --fixup <sha> | Marked for autosquash on rebase |
| git restore --staged file | Unstage without losing changes |
| git restore file | Discard local edits (DANGER) |
Rebase & merge
| git rebase main | Replay your commits on top of main |
| git rebase -i HEAD~5 | Interactive: squash, reword, drop, reorder |
| git rebase --autosquash -i main | Apply --fixup commits automatically |
| git merge --no-ff feature/x | Force a merge commit (preserves history) |
| git rebase --continue / --abort | After resolving conflicts |
Stash, cherry-pick, tag
| git stash push -m 'wip' | Stash with message |
| git stash list / pop / apply | List / restore + delete / restore + keep |
| git cherry-pick <sha> | Apply one commit onto current branch |
| git cherry-pick -x <sha> | Adds 'cherry picked from' to message |
| git tag -a v1.0 -m 'release' | Annotated tag |
| git push origin v1.0 | Push a single tag |
Inspecting history
| git log --oneline --graph --all | Visual history |
| git log -S 'searchText' | Find commits adding/removing that string |
| git log -p file | Per-line history of a file |
| git blame file | Who last touched each line |
| git diff --stat | Files changed + insertions/deletions |
| git show <sha> | Patch for a single commit |
🚨 Rescue operations
| git reflog | Time machine — every HEAD move, even after reset |
| git reset --hard HEAD@{2} | Jump back to a reflog state |
| git reset --soft HEAD~1 | Undo last commit, keep changes staged |
| git reset --mixed HEAD~1 | Undo last commit, unstage changes |
| git reset --hard origin/main | Discard everything, match remote (DANGER) |
| git revert <sha> | Create a NEW commit that undoes <sha> |
| git checkout <sha> -- file | Restore single file from a past commit |
| git fsck --lost-found | Find dangling commits/blobs (after force-push) |
| git push --force-with-lease | Force push BUT abort if remote moved |
Worktrees & submodules
| git worktree add ../hotfix main | Check out main in a sibling folder |
| git worktree list / remove | Manage worktrees |
| git submodule update --init --recursive | Pull submodule contents |
Want the full hands-on training behind this?
Cloudadhar batches walk you through every command in a real production setup — with labs, code reviews, and 1:1 doubt sessions.