12 git aliases that save me 30 minutes a day
· Tutorials
30 minutes a day, 180 hours a year. 12 git aliases I actually use — navigation, editing, log views, cleanup. Copy my .gitconfig and skip the research.
30 minutes a day, 180 hours a year. These 12 git aliases are the ones I actually use after 2 years of trial. Navigation, editing, log views, cleanup — copy my .gitconfig and skip the research.
The aliases
Drop these in ~/.gitconfig under [alias]:
# ── Logging ───────────────────────────────────────────── lg = log --graph --oneline --decorate --abbrev-commit lgg = log --graph --oneline --decorate --stat --abbrev-commit last = log -1 HEAD --stat recent = for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
# ── Diffing ──────────────────────────────────────────── d = diff dc = diff --cached dw = diff --word-diff
# ── Committing ───────────────────────────────────────── c = commit -m ca = commit --amend --no-edit cam = commit --amend -m
# ── Cleanup ───────────────────────────────────────────── prune-branches = "!git branch --merged | grep -v '\\\\|main\\|master\\|develop' | xargs -n 1 git branch -d" undo = reset --soft HEAD~1 undoh = reset --hard HEAD~1
What each one does — and why
s — short status
The default git status is verbose. git s gives you the branch state + tracking info + changed files in 3 lines. I run this 50+ times a day.
lg — readable log graph
The graph shows branch structure at a glance. lg is my daily driver. lgg adds file stats — useful for code review.
last — what did I just commit?
Saves the git log -1 HEAD --stat typing. Especially useful after a merge when you want to see what landed.
recent — branches by last commit
Answers "what was I working on last week?" — sorted by activity, not alphabetically. Indispensable when context-switching between projects.
ca — amend without opening editor
The most-used alias in my workflow. Forgot to add a file? git add . && git ca. Typo in the last commit? git add . && git ca and recommit.
undo — soft reset
For when you commit too early. Changes go back to staging — recommit with a better message or split into smaller commits.
undoh — hard reset (be careful)
Nuclear option. I use this maybe once a month — usually after a 30-minute experiment that didn't work. Don't alias this if you're afraid of yourself.
prune-branches — cleanup
Deletes every merged branch except main, master, and develop. Run this after every PR merge — keeps your local branch list manageable.
The bonus aliases I couldn't live without
cob — create + checkout branch
Two steps in one. Same as git checkout -b but shorter.
dc — diff cached (what am I about to commit?)
Run this before every commit. Saves the "wait, did I stage the wrong file?" panic.