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
| Command | What it does | |
|---|---|---|
| git status -sb | Short status with branch and tracking info | |
| git log --oneline --graph --decorate | Readable history with branch topology | |
| git diff --staged | What is actually about to be committed | |
| git blame -L 10,20 file | Who last touched those lines, and when |
Undoing
The first three are safe. The last rewrites history.
| Command | What it does | |
|---|---|---|
| git restore file | Discard unstaged changes to a file | |
| git restore --staged file | Unstage 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
| Command | What it does | |
|---|---|---|
| git switch -c feature/x | Create and move to a branch | |
| git rebase -i HEAD~5 | Reorder, squash or reword the last five commits | |
| git cherry-pick <sha> | Apply one commit onto the current branch | |
| git push --force-with-lease | Force push that refuses if someone else pushed first |
Rescue
| Command | What it does | |
|---|---|---|
| git reflog | Every position HEAD has held. Almost nothing is truly lost. | |
| git stash push -m 'wip' | Shelve changes with a label | |
| git bisect start | Binary search the history for the commit that broke it | |
| git fsck --lost-found | Recover 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.