Skip to content
DDevToolery

Git commands

Grouped by what you are trying to do rather than alphabetically, because that is how you look them up under pressure.

16 entries

Inspecting

CommandWhat it does
git status -sbShort status with branch and tracking info
git log --oneline --graph --decorateReadable history with branch topology
git diff --stagedWhat is actually about to be committed
git blame -L 10,20 fileWho last touched those lines, and when

Undoing

The first three are safe. The last rewrites history.

CommandWhat it does
git restore fileDiscard unstaged changes to a file
git restore --staged fileUnstage without losing the edit
git revert <sha>New commit undoing an old one — safe on shared branches
git reset --hard <sha>Move the branch and destroy working changes. No undo.

Branching

CommandWhat it does
git switch -c feature/xCreate and move to a branch
git rebase -i HEAD~5Reorder, squash or reword the last five commits
git cherry-pick <sha>Apply one commit onto the current branch
git push --force-with-leaseForce push that refuses if someone else pushed first

Rescue

CommandWhat it does
git reflogEvery position HEAD has held. Almost nothing is truly lost.
git stash push -m 'wip'Shelve changes with a label
git bisect startBinary search the history for the commit that broke it
git fsck --lost-foundRecover dangling objects after a bad reset

--force-with-lease should be your default over --force: it aborts if the remote moved, which is exactly the case where forcing destroys someone else's work.