git commands for the situations that happen

not a full reference. the commands I actually reach for when something's gone sideways

01
git commit --amend
fix the last commit message or slip in a forgotten file, before you push. after you push this gets messy
02
git reset --soft HEAD~1
03
git stash && git stash pop
save uncommitted work to switch branches, then bring it back. forgetting the pop is how you lose an afternoon
04
git rebase -i HEAD~5
squash or reorder the last 5 commits before a pr. scary at first, pick/squash/drop are all you need. git rebase --abort exists for a reason
05
git cherry-pick <commit>
06
git reflog
the command that has saved me more than any other. every ref move is logged here, even after a hard reset
07
git restore .
08
git branch -D <branch>
09
git log --oneline --graph --all
see the actual shape of the branch history, not just a list of commits
10
git bisect start
binary search through commits to find which one broke something. you will look this up again every time, nobody remembers the syntax
11
git push --force-with-lease
force push but it fails if someone else pushed since your last fetch. use this, never plain --force
12
git diff --staged