Git Quick Reference

The commands I reach for every day.

Repository setup

git init                        # new repo
git clone <url>                 # clone remote
git clone --recurse-submodules  # with submodules

Staging & committing

git status                      # what's changed
git add .                       # stage all
git add -p                      # interactive staging
git commit -m "message"
git commit --amend              # edit last commit

Branching

git branch                      # list branches
git branch <name>               # create branch
git checkout -b <name>          # create + switch
git switch <name>               # switch (modern)
git branch -d <name>            # delete

Remote

git remote -v                   # list remotes
git fetch                       # fetch without merging
git pull                        # fetch + merge
git push origin <branch>
git push -u origin <branch>     # set upstream

Undo

git restore <file>              # discard working tree changes
git reset HEAD <file>           # unstage
git reset --soft HEAD~1         # undo last commit (keep changes)
git revert <hash>               # safe undo (creates new commit)