Git Commands Cheat Sheet
# Git Commands Cheat Sheet
The commands you reach for every day.
Setup & basics
| Command | What it does |
|---|---|
git init | Start a new repository |
git clone <url> | Copy a remote repository |
git status | Show working-tree state |
git add <file> | Stage changes |
git commit -m "msg" | Record staged changes |
Branching & merging
| Command | What it does |
|---|---|
git branch | List branches |
git switch -c <name> | Create and switch to a branch |
git merge <branch> | Merge a branch into current |
git rebase <branch> | Reapply commits on top of another base |
Remotes
| Command | What it does |
|---|---|
git remote -v | List remotes |
git fetch | Download remote changes |
git pull | Fetch + merge |
git push | Upload commits |
Undoing things
| Command | What it does |
|---|---|
git restore <file> | Discard working changes |
git reset --soft HEAD~1 | Undo last commit, keep changes staged |
git revert <commit> | Create a commit that undoes another |