Git Survival Guide
The commands you actually reach for — daily flow, undo anything, branches, and the ones you google every time.
Daily flow
- git status -sb
- short status + branch — alias it
- git add -p
- stage hunk by hunk — the single best habit
- git commit --amend
- fix the last commit (message or staged files)
- git pull --rebase
- update without merge-commit noise
- git push --force-with-lease
- force-push that refuses to clobber teammates
- git stash / stash pop
- shelve work;
stash -uincludes untracked
Undo anything
- Unstage a file
git restore --staged f- Discard local edits
git restore f(gone for real — careful)- Undo last commit, keep work
git reset --soft HEAD~1- Undo a pushed commit
git revert <sha>— new inverse commit, history intact- Find lost commits
git reflog— everything you ever pointed at, 90 days- Recover from any mess
- reflog →
git reset --hard <good-sha>
Branches & history
- git switch -c feat
- create + switch (modern
checkout -b) - git rebase -i main
- squash/reword/drop before the PR
- git cherry-pick sha
- copy one commit onto this branch
- git log --oneline --graph
- the readable history view
- git bisect
- binary-search history for the breaking commit
- git blame -w -C
- who wrote it — ignoring whitespace and moves
The ones you google
- Rename branch
git branch -m new(+ push and set upstream)- Delete remote branch
git push origin --delete old- One file from another branch
git restore --source main -- f- What changed vs main
git diff main...HEAD(three dots: since fork point)- Untrack a committed file
git rm --cached f+ .gitignore