Kindsnippet
Maturitybudding
Confidencehigh
Originai-drafted
Created
Tagsgit, reference
Markdown/snippet/git-commands-i-use.md
See what AI agents see
🤖 This content is AI-generated. What does this mean?
snippet 🪴 budding 🤖 ai-drafted

Git Commands I Actually Use

The 20% of git that covers 95% of daily work — no theory, just commands.

Daily

Terminal window
# What changed?
git status
git diff # unstaged changes
git diff --staged # staged changes (about to commit)
# Commit
git add -p # stage hunks interactively — review what you're committing
git commit -m "message"
# Sync
git pull --rebase # pull without merge commits
git push

Branching

Terminal window
# Create and switch
git checkout -b feature/thing
git switch -c feature/thing # modern equivalent
# Switch back
git checkout main
git switch main
# Delete after merge
git branch -d feature/thing # safe — refuses if unmerged
git branch -D feature/thing # force — deletes regardless

Checking History

Terminal window
# Recent commits
git log --oneline -10
git log --oneline --graph --all # visual branch topology
# What changed in a commit?
git show abc1234
git show abc1234 --stat # files only, no diff
# Who changed this line?
git blame src/lib/auth.ts
# Search commit messages
git log --grep="fix auth"
# Find when a string was added/removed
git log -S "functionName" --oneline

Undoing Things

Terminal window
# Unstage a file (keep changes)
git restore --staged file.ts
# Discard local changes to a file
git restore file.ts
# Amend the last commit (message or content)
git add forgotten-file.ts
git commit --amend
# Undo last commit but keep changes staged
git reset --soft HEAD~1
# Undo last commit, unstage changes
git reset HEAD~1

Working with Remotes

Terminal window
# See what's out there
git remote -v
git fetch --all
# Check divergence from upstream
git rev-list --left-right --count main...upstream/main
# Output: "18 29" means 18 ahead, 29 behind
# Rebase onto upstream
git fetch upstream
git rebase upstream/main

Stashing

Terminal window
# Save work in progress
git stash
git stash push -m "wip: auth refactor"
# Get it back
git stash pop # apply and remove from stash
git stash apply # apply but keep in stash
# List stashes
git stash list

Useful 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