git commands i always forget

@sam_ships3 events in the last 7 days41030 forks12 items#git#cheat-sheet

too niche for the official cheat sheet, common enough that i keep googling them

1
git reflog
the one that's saved me from a bad reset more times than i'll admit
2
git rebase -i HEAD~5
interactive rebase to squash commits before a pr. always forget the tilde number i actually need
3
git commit --fixup <hash>
pairs with rebase --autosquash. huge once it clicks, ymmv how long that takes
4
git rebase --autosquash
5
git bisect start
binary search through history for the commit that broke something. underused, i forget the syntax every time
6
git stash pop
not git stash apply. pop actually removes it from the stash list, apply leaves a copy sitting there
7
git cherry-pick -x <hash>
records which commit it came from in the message. worth it on shared branches
8
git worktree add ../hotfix branch-name
9
git log --oneline --graph --all
alias this immediately on every new machine and still type it out longhand half the time anyway
10
git diff --staged
shows what's actually about to be committed, not the working tree diff
11
git remote prune origin
cleans up stale remote branches locally. do this before you panic about a branch that's "gone"
12
git blame -L 10,20 -- file.js
blame just a line range instead of the whole file's history scrolling past

Or start a list of your own — free, it takes a minute.