Dev

Git aliases that deleted my 3am oncall shifts

I've been doing this for 12 years and most engineers are still typing 'git log --oneline --graph --decorate --all' by hand. That's not discipline. That's self-harm. Here are the aliases that actually live in my .gitconfig.

Git aliases that deleted my 3am oncall shifts

In 2021, at a fintech startup with about 200 engineers, we did a postmortem on a bad deploy. Took us 47 minutes to identify which commit introduced the regression. Forty-seven minutes. The incident cost roughly $340k in refunds and SLA credits. Not because our systems were bad. Because three engineers were fumbling through git log output in a terminal like it was 1998.

I put these aliases in everyone's dotfiles the next week. Never had that problem again.

The ones I actually use

First, the log. This is the one everyone should have and almost nobody does:

lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

Run git lg on any repo and you'll see a visual branch graph with short hashes, author names, and relative timestamps. The default git log is a crime against productivity. This fixes it.

Next, finding what changed between you and main:

incoming = log HEAD..origin/main --oneline
outgoing = log origin/main..HEAD --oneline

Here's the thing. Before a rebase or a merge, you need to know what you're walking into. I've seen engineers rebase onto main without checking incoming and blow away three days of work. Don't do this without running git incoming first.

The one that's saved me the most

undo = reset HEAD~1 --mixed

Soft undo. Keeps your changes staged. The number of times I've committed something and immediately realized I included a debug log or a wrong file... this is muscle memory now. I type git undo before I even feel the regret.

Don't confuse this with --hard. Hard resets have a body count. I've seen this kill production config files that weren't tracked. Mixed is the safe default.

The ones for code review hell

aliases = !git config --list | grep alias
branches = branch -a --sort=-committerdate --format='%(refname:short) %(committerdate:relative)'

The branches alias is underrated. Sorted by most recently touched. When you're context switching across four feature branches and can't remember which one you were on Tuesday, this is the answer. Pure sorted clarity.

aliases is just a sanity check. Because six months from now you won't remember what you configured and you'll be Googling it. Just run git aliases.

One more. The nuclear option.

nuke = !git clean -fd && git checkout .

Blows away all untracked files and reverts everything to HEAD. I use this when a local environment is so corrupted I just want to start clean. It's dangerous. It's also fast. Run it knowing exactly what it does, or don't run it at all.

I've watched engineers spend 40 minutes trying to manually undo a webpack config change that broke their local build. One git nuke and it's done in three seconds.

Where to put these

Your ~/.gitconfig under [alias]. Or use git config --global alias.lg "log --graph...". Either works. Share it with your team in a dotfiles repo. We use a shared one at Stripe that new engineers get on day one. Onboarding time for getting comfortable in the codebase dropped noticeably after we standardized this.

The point isn't the aliases themselves. The point is that your tools should make the right thing the easy thing. Right now, for most of you, the right thing requires typing 60 characters from memory. That's a problem you can fix in ten minutes.

OPEN IN REEDL_ FEED →← Back to feed