Skip to content

Git Quick Ref

Git Quick Reference

The commands that cover 95% of this course.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# --- Where am I? Ask constantly. ---
git status
git log --oneline --graph --all
git branch -a

# --- The daily loop ---
git switch main && git pull
git switch -c week-NN-pattern
git add <files>
git commit -m "feat: ..."
git push -u origin week-NN-pattern     # first time
git push                                # after that

# --- Undo, gentlest to harshest ---
git restore <file>              # discard unstaged edits to a file
git restore --staged <file>     # unstage, keep the edit
git commit --amend              # fix the last UNPUSHED commit
git revert <hash>               # new commit undoing an old one (SAFE)
git reset --hard <hash>         # ⚠️ rewrite history, discard changes
git reflog                      # find "lost" commits — the safety net

The panic table

Situation Command Danger
Wrong file edited, not staged git restore <file> loses that edit
Staged by mistake git restore --staged <file> safe
Bad message (not pushed) git commit --amend -m "..." safe if unpushed
Committed to main by mistake git switch -c rescue, then reset main safe
Committed build output git rm -r --cached <dir> + .gitignore safe
Merge conflict edit markers → git addgit commit safe
Want out of a merge git merge --abort safe
Undo a pushed commit git revert <hash> safe — prefer this
“I lost commits” git reflog safe

One rule above all: if the work is committed anywhere, it’s recoverable. git reflog will find it. The only work Git can’t save is work you never committed — which is the real argument for committing often.