Git Quick Cheat Sheet
git cheatsheet command
Fast lookup for the commands you actually use. Replace placeholders like <file>, <branch>, <name>, and <commit>.
Quick Index
Status / Inspect
| Command | What it does |
|---|
git status | What changed + what’s staged. |
git diff | Unstaged changes. |
git diff --staged | Staged changes (not committed). |
git log --oneline --decorate --graph -n 20 | Quick recent history graph. |
Stage / Commit
| Command | What it does |
|---|
git add <file> | Stage file. |
git add . | Stage all changes. |
git commit -m "msg" | Commit staged changes. |
git commit --amend | Fix last commit (only if not pushed). |
git reset <file> | Unstage file (keeps edits). |
Branches
| Command | What it does |
|---|
git branch | List branches. |
git checkout -b <name> | New branch + switch (classic). |
git checkout <name> | Switch branch (classic). |
git switch -c <name> | New branch + switch (modern). |
git switch <name> | Switch branch (modern). |
git merge <name> | Merge <name> into current branch. |
Remotes
| Command | What it does |
|---|
git remote -v | Show remotes. |
git fetch origin | Download remote updates only. |
git pull origin <branch> | Fetch + merge. |
git push origin <branch> | Push branch. |
git push -u origin <branch> | Push + set upstream tracking. |
Undo / Park Work
| Task | Command |
|---|
| Revert a commit safely (works after push) | git revert <commit> |
| Hard reset to a commit (danger) | git reset --hard <commit> |
| Stash work | git stash |
| Stash including untracked | git stash -u |
| Re-apply stash | git stash pop |
Rule of thumb: If it is already pushed, prefer revert over reset --hard.
Create / Clone
| Command | What it does |
|---|
git clone <url> | Clone repo. |
git init | Init repo in folder. |
Do this a lot workflows
New repo: first push to main
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <repo_url>
git push -u origin main
Feature branch and push
git checkout -b feature/my-change
# work...
git add .
git commit -m "My change"
git push -u origin feature/my-change
Update your feature branch with latest main (merge)
git checkout main
git pull origin main
git checkout feature/my-change
git merge main
Help
git help <command>