Skip to content
Latchkey

Git Cheat Sheet: Everyday Commands and Recovery

The Git commands you use daily, and the recovery ones you need when things go wrong.

Branch, commit, sync, and undo - the Git essentials.

Branch & commit

CommandDoes
git switch -c nameNew branch
git add -pStage interactively
git commit -m "msg"Commit
git push -u origin namePush + track
git pull --rebaseUpdate, rebasing local commits

Inspect

CommandDoes
git status -sbShort status
git log --oneline --graphCompact history
git diff --stagedStaged changes
git blame fileWho changed each line

Undo & recover

CommandDoes
git restore fileDiscard working changes
git restore --staged fileUnstage
git commit --amendFix last commit
git reset --soft HEAD~1Undo commit, keep changes
git reflogFind lost commits
git revert SHASafe undo (new commit)

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →