Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

git aliases that earn their keep

A handful of git aliases I actually use every day, and why the boring ones save more time than the clever ones.

A mechanical keyboard lit by a terminal

Every so often someone shares their .gitconfig and it's forty aliases deep, half of them aliases for aliases, and you can tell they wrote each one once in a fit of enthusiasm and never used it again. I've trimmed mine down hard. The test is simple: if I haven't typed it in a month, it goes. What's left has earned its place by sheer repetition.

Here's the [alias] block as it stands today.

[alias]
    st = status -sb
    co = checkout
    br = branch
    ci = commit
    last = log -1 HEAD --stat
    unstage = reset HEAD --
    lg = log --graph --oneline --decorate --all
    amend = commit --amend --no-edit
    wip = !git add -A && git commit -m wip
    undo = reset --soft HEAD~1

None of these are clever, and that's the point.

the boring ones do the heavy lifting

st = status -sb is the one I lean on most. The short format with the branch line gives me everything I want in three or four lines instead of the wall of text that plain status throws up. After a few thousand invocations the saved scrolling alone justifies it.

unstage and undo are the two I reach for when I've fumbled. git reset HEAD -- is not a command I want to type from memory at half past five when I've accidentally staged a whole vendored directory. Giving it a name I can remember turns a moment of mild panic into a reflex.

Lines of source code on a dark terminal

wip and amend are a pair. wip is a deliberately scrappy commit so I can switch branches without stashing, the kind of thing I'll squash later and would be embarrassed to push. amend = commit --amend --no-edit fixes the commit I just made when I spot the typo two seconds after hitting enter. The --no-edit is the bit that matters: I almost never want to rewrite the message, I just want the file in there.

the one that looks clever but isn't

lg is the graph log, and it's the closest thing here to showing off. But I genuinely use it to work out what happened on a branch I haven't touched in a week, especially when a merge has gone sideways and I need to see where the lines actually diverged. The --all flag is the difference between a useful picture and a confusing one, because it shows every branch, not just the one I'm sitting on.

A couple of things I deliberately don't alias. git push --force stays long, because the friction is the feature. Anything that rewrites published history should make me type the whole thing out and think about it. And I've stopped aliasing pull, because I want to know whether I'm rebasing or merging each time rather than baking a default into a two-letter command.

That's it. Ten aliases, all of them dull, all of them used daily. If you take one thing from this, make it st. The rest you'll grow into, or you won't, and either way your config stays honest.