Five git aliases I use every single day
Small shortcuts that save me hundreds of keystrokes a week, and one that saved an entire afternoon of work.
I type git more than I type my own name. At some point I noticed I was typing the same long commands over and over, so I gave them nicknames. Here are the five I’d miss the most.
1. A log you can actually read
The default git log is a wall of text. This one gives you a compact, colorful graph:
git config --global alias.lg "log --graph --oneline --decorate --all"
Now git lg shows every branch, where they split, and where they merged. It’s the alias I show people first.
2. “Wait, what did I just change?”
git config --global alias.last "log -1 HEAD --stat"
git last shows your most recent commit and which files it touched. Perfect for the moment right after you commit and immediately doubt yourself.
3. Undo the last commit (but keep the work)
git config --global alias.undo "reset --soft HEAD~1"
Committed too early? Typo in the message? git undo rewinds the commit but leaves all your changes staged, exactly as they were.
4. Clean up merged branches
git config --global alias.tidy "!git branch --merged | grep -vE '^\*|main|master' | xargs -n 1 git branch -d"
git tidy deletes every local branch that’s already been merged. Mine went from 47 branches to 3. It felt like cleaning out a closet.
5. The one that saved an afternoon
git config --global alias.wip "!git add -A && git commit -m 'WIP' --no-verify"
git wip snapshots everything in one go. I use it before any risky operation: a rebase, a big refactor, switching branches mid-thought. If it all goes wrong, the work is safe in a commit and I can git undo it later.
The day I learned this, I had just lost three hours of work to a bad git checkout .. Never again.
Quick check 🧠
You committed with a typo in the message and haven't pushed yet. Which alias fixes it while keeping your changes?
git undo runs reset --soft HEAD~1: the commit disappears, but every change stays staged so you can commit again with the right message.
Try it yourself
Tick these off as you go. Your progress is saved in this browser, so you can come back later.
Set up your aliases
0/4
All done. Look at you go! ✨
Got a favorite alias I didn’t mention? I’m always collecting new ones.