Git Cheat Sheet
The Git commands I actually use day to day, plus how to undo things safely.
~2 min read updated Jul 17, 2026 Git
#git #cli #version-control #cheat-sheet
The 20% of Git that covers 80% of the work — plus the handful of recovery commands that turn "I broke everything" into a two-minute fix.
Everyday flow
git status # what's changed
git add -p # stage hunks interactively
git commit -m "feat: add search"
git pull --rebase # avoid noisy merge commits
git push
Branching
| Command | Does |
|---|---|
git switch -c feature/x | Create and switch to a branch |
git switch main | Switch back |
git branch -d feature/x | Delete a merged branch |
git branch -D feature/x | Force-delete an unmerged branch |
Undoing things
The difference between
--soft, --mixed and --hard is what happens to your
changes. --hard throws work away — be sure before you run it.git commit --amend # fix the last commit message or add staged files
git restore --staged file.ts # unstage, keep changes
git restore file.ts # discard uncommitted changes to a file
git reset --soft HEAD~1 # undo last commit, keep changes staged
git reset --mixed HEAD~1 # undo last commit, keep changes unstaged
git reset --hard HEAD~1 # undo last commit AND discard changes
Stashing
git stash # shelve changes
git stash pop # bring them back
git stash list # see the stack
git stash -u # include untracked files
The panic button: reflog
git reflog records every position HEAD has been at, even after a "destructive"
reset. Almost nothing is truly lost for ~90 days.git reflog # find the SHA you were at before the mistake
git reset --hard abc1234 # jump back to it
Rewriting history (local branches only)
git rebase -i HEAD~3 # squash, reorder or reword the last 3 commits
git cherry-pick abc1234 # copy a single commit onto the current branch
Never rewrite history that others have already pulled. Rebasing a shared branch
forces everyone else into a painful recovery.
Git
Version control — everyday commands and getting out of trouble.
Teaching
Lesson plans, activities, rubrics and student references.