git reference (all-in-one)

Concise commands for daily work, branching, recovery, and release hygiene.

daily driver

TaskCommand
Clonegit clone <url>
Status (short)git status -sb
Stage all / unstage filegit add -A · git restore --staged <file>
Commitgit commit -m "message"
Pull with rebasegit pull --rebase origin main
Push current branchgit push -u origin HEAD
Show last commitgit show --stat

branches & merges

TaskCommand
List branches (local + remote)git branch -a
Create / switchgit switch -c feature · git switch feature
Merge into currentgit merge feature
Abort mergegit merge --abort
Rebase branchgit rebase main
Resolve conflictsedit files → git addgit rebase --continue or git commit
Delete branchgit branch -d feature (safe) · -D (force)
Delete remote branchgit push origin --delete feature

history & diff

TaskCommand
Graph viewgit log --oneline --graph --decorate --all
Blame filegit blame <file>
Diff staged / workinggit diff --cached · git diff
Diff vs branchgit diff main..feature
Find introducing commitgit log -S 'string' -- <file>

stash & cherry-pick

TaskCommand
Stash with notegit stash push -m \"wip: api fix\"
List / apply / dropgit stash list · git stash apply stash@{1} · git stash drop
Cherry-pick commitgit cherry-pick <sha>
Cherry-pick rangegit cherry-pick A^..B

reset & recover

ActionCommand
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 safelygit revert <sha>
Recover deleted branchgit reflog → find SHA → git checkout -b restored <sha>

tags & releases

TaskCommand
Lightweight / annotatedgit tag v1.2.0 · git tag -a v1.2.0 -m \"Release\"
Push tagsgit 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

TaskCommand
View remotesgit remote -v
Add / rename / removegit remote add upstream <url> · git remote rename origin old · git remote remove old
Prune dead branchesgit fetch --prune
Set upstream after clonegit 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

TaskCommand
Addgit submodule add <repo> path/inside
Init & updategit submodule update --init --recursive
Clone with submodulesgit 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