snippet budding 🤖 ai-drafted
Git Commands I Actually Use
The 20% of git that covers 95% of daily work — no theory, just commands.
Daily
# What changed?git statusgit diff # unstaged changesgit diff --staged # staged changes (about to commit)
# Commitgit add -p # stage hunks interactively — review what you're committinggit commit -m "message"
# Syncgit pull --rebase # pull without merge commitsgit pushBranching
# Create and switchgit checkout -b feature/thinggit switch -c feature/thing # modern equivalent
# Switch backgit checkout maingit switch main
# Delete after mergegit branch -d feature/thing # safe — refuses if unmergedgit branch -D feature/thing # force — deletes regardlessChecking History
# Recent commitsgit log --oneline -10git log --oneline --graph --all # visual branch topology
# What changed in a commit?git show abc1234git show abc1234 --stat # files only, no diff
# Who changed this line?git blame src/lib/auth.ts
# Search commit messagesgit log --grep="fix auth"
# Find when a string was added/removedgit log -S "functionName" --onelineUndoing Things
# Unstage a file (keep changes)git restore --staged file.ts
# Discard local changes to a filegit restore file.ts
# Amend the last commit (message or content)git add forgotten-file.tsgit commit --amend
# Undo last commit but keep changes stagedgit reset --soft HEAD~1
# Undo last commit, unstage changesgit reset HEAD~1Working with Remotes
# See what's out theregit remote -vgit fetch --all
# Check divergence from upstreamgit rev-list --left-right --count main...upstream/main# Output: "18 29" means 18 ahead, 29 behind
# Rebase onto upstreamgit fetch upstreamgit rebase upstream/mainStashing
# Save work in progressgit stashgit stash push -m "wip: auth refactor"
# Get it backgit stash pop # apply and remove from stashgit stash apply # apply but keep in stash
# List stashesgit stash listUseful Aliases
Add to ~/.gitconfig:
[alias] s = status --short l = log --oneline -20 d = diff ds = diff --staged co = checkout cb = checkout -b amend = commit --amend --no-edit last = log -1 --stat branches = branch -a --sort=-committerdate