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

the handful of git aliases i actually type

A short tour of the git aliases that survived years of pruning, the ones I reach for daily, plus the principle of why most aliases die and these few did not.

A mechanical keyboard lit over a terminal

Everyone's dotfiles accumulate git aliases the way a drawer accumulates pens, and most of them never get used twice. I went through mine recently and deleted about two-thirds of them without a flicker of loss. These are the ones that survived, the handful I genuinely type every day, because they each remove a real and frequent annoyance rather than just saving a few keystrokes on something I do once a month.

A close-up of the config the aliases live in

The clear winner is a readable log. Git's default log is a wall of text; this one fits the history on screen and I can actually parse it at a glance:

[alias]
    lg = log --graph --abbrev-commit --decorate \
         --format=format:'%C(bold blue)%h%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' \
         --all

git lg is probably the single command I run most, full stop. The graph and the colours mean I understand the branch state in a second rather than scrolling.

Next, the small ones that fix daily friction:

[alias]
    st = status -sb
    co = checkout
    br = branch
    amend = commit --amend --no-edit
    unstage = reset HEAD --
    last = show --stat HEAD

st gives the short, branch-aware status, which is all I want ninety per cent of the time. amend --no-edit is the one I would miss most after lg: I fix the typo, stage it, git amend, and the last commit absorbs the change without making me re-confirm the message I already wrote. unstage exists purely because I can never remember that the way to unstage a file is the deeply unobvious reset HEAD --, so I hid it behind a word that means what it does.

The one with a slightly cleverer trick is a tidy-up for merged branches:

[alias]
    gone = "!git branch -vv | grep ': gone]' | awk '{print $1}' | xargs -r git branch -d"

git gone deletes local branches whose upstream has been deleted, which after a few months of merged pull requests is most of them. The ! prefix runs it as a shell command rather than a git subcommand, which is the escape hatch that makes aliases properly useful: anything you can write in a shell, you can name.

That is the whole principle, really. An alias earns its keep when it removes a daily papercut or hides a command I will never memorise, like reset HEAD --. The ones I deleted were clever shortcuts for things I do rarely, where the cleverness was the cost: I could never remember the alias existed, so I typed the long form anyway. Keep the few you reach for without thinking, and let the rest go.