git reference (all-in-one)
Concise commands for daily work, branching, recovery, and release hygiene.
daily driver
| Task | Command |
| Clone | git clone <url> |
| Status (short) | git status -sb |
| Stage all / unstage file | git add -A · git restore --staged <file> |
| Commit | git commit -m "message" |
| Pull with rebase | git pull --rebase origin main |
| Push current branch | git push -u origin HEAD |
| Show last commit | git show --stat |
branches & merges
| Task | Command |
| List branches (local + remote) | git branch -a |
| Create / switch | git switch -c feature · git switch feature |
| Merge into current | git merge feature |
| Abort merge | git merge --abort |
| Rebase branch | git rebase main |
| Resolve conflicts | edit files → git add → git rebase --continue or git commit |
| Delete branch | git branch -d feature (safe) · -D (force) |
| Delete remote branch | git push origin --delete feature |
history & diff
| Task | Command |
| Graph view | git log --oneline --graph --decorate --all |
| Blame file | git blame <file> |
| Diff staged / working | git diff --cached · git diff |
| Diff vs branch | git diff main..feature |
| Find introducing commit | git log -S 'string' -- <file> |
stash & cherry-pick
| Task | Command |
| Stash with note | git stash push -m \"wip: api fix\" |
| List / apply / drop | git stash list · git stash apply stash@{1} · git stash drop |
| Cherry-pick commit | git cherry-pick <sha> |
| Cherry-pick range | git cherry-pick A^..B |
reset & recover
| Action | Command |
| Soft reset (keep staged) | git reset --soft <sha> |
| Mixed reset (default) | git reset <sha> |
| Hard reset (discard work) | git reset --hard <sha> |
| Undo a commit safely | git revert <sha> |
| Recover deleted branch | git reflog → find SHA → git checkout -b restored <sha> |
tags & releases
| Task | Command |
| Lightweight / annotated | git tag v1.2.0 · git tag -a v1.2.0 -m \"Release\" |
| Push tags | git push origin v1.2.0 · git push origin --tags |
| Delete tag (local/remote) | git tag -d v1.2.0 · git push origin :refs/tags/v1.2.0 |
remotes & hygiene
| Task | Command |
| View remotes | git remote -v |
| Add / rename / remove | git remote add upstream <url> · git remote rename origin old · git remote remove old |
| Prune dead branches | git fetch --prune |
| Set upstream after clone | git branch --set-upstream-to origin/main |
bisect (find bad commit)
git bisect start
git bisect bad # current commit has the bug
git bisect good <good_sha> # known good point
# test... mark each step:
git bisect good | git bisect bad
git bisect reset # when done
submodules
| Task | Command |
| Add | git submodule add <repo> path/inside |
| Init & update | git submodule update --init --recursive |
| Clone with submodules | git clone --recurse-submodules <repo> |
helpful config snippets
# One-time setup
git config --global pull.rebase true
git config --global fetch.prune true
git config --global init.defaultBranch main
# Aliases
git config --global alias.st 'status -sb'
git config --global alias.lg 'log --oneline --graph --decorate'
git config --global alias.co 'checkout'
git config --global alias.br 'branch'
Return to Home