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

The Five Git Aliases I'd Miss On A New Machine

A short, opinionated set of git aliases I actually use daily, and what each one saves me from typing.

A keyboard and terminal

Everyone has a .gitconfig full of aliases they copied off a gist in 2015 and never use. I've trimmed mine down to the handful I'd actually feel the loss of on a fresh machine. The test is simple: if my fingers reach for it before my brain does, it stays.

[alias]
    s = status -sb
    last = log -1 HEAD --stat
    undo = reset --soft HEAD~1
    please = push --force-with-lease
    lg = log --oneline --graph --decorate -20

s is just status with less noise, and I type it a hundred times a day. last shows me the commit I just made with its files, which is how I catch the "oh, I committed the debug print" mistake before I push it.

undo is the one I'd genuinely miss. It un-commits the last commit but keeps the changes staged, so it's not destructive, it just rewinds the commit itself. Far calmer than trying to remember whether I want --soft, --mixed, or the one that eats your work.

please is the real prize. push --force-with-lease refuses to clobber the remote if someone else has pushed since you last fetched, which is the entire difference between force-pushing safely and force-pushing into a colleague's afternoon. Naming it please means I have to ask nicely, and the lease means git is allowed to say no. Both of those are features.