Git Cheatsheet
Everyday Git commands. Each row is 'what you do' → 'how you do it'.
1 credit
Setup
5 itemsConfigure user
git config --global user.name "Your Name"Configure email
git config --global user.email "you@example.com"Default branch
git config --global init.defaultBranch mainInitialize repo
git initClone repo
git clone <url>Staging & committing
6 itemsStatus
git statusStage file
git add <path>Stage all
git add -AUnstage
git restore --staged <path>Commit
git commit -m "message"Amend last
git commit --amendBranches
5 itemsList
git branch -aCreate + switch
git switch -c <name>Switch
git switch <name>Delete local
git branch -d <name>Rename
git branch -m <old> <new>Remote & sync
5 itemsFetch
git fetch originPull --rebase
git pull --rebase origin mainPush
git push origin <branch>Push new branch
git push -u origin <branch>Force-with-lease
git push --force-with-leaseUndo / rescue
6 itemsDiscard file changes
git restore <path>Reset soft (keep work)
git reset --soft HEAD~1Reset hard (destructive)
git reset --hard HEAD~1Recover via reflog
git reflogStash
git stash push -m "msg"Stash pop
git stash pop