Saying stuff about stuff.

Git aliases that make my life easier

Before thinking about aliases the best thing you can do to make git nicer to use is configure tab completion. If you’re using Homebrew follow their shell completion docs otherwise you’re on your own – but do it! The great thing about git aliases is that they’re also tab completable.

Here are the git aliases I use all the time, add them to your ~/.gitconfig:

[alias]
  browse = !gh browse
  co = checkout
  recent = branch --sort=-committerdate
  st = status
  touch = commit --amend --date=now --no-edit

First of all git co and git st are a throwback to my SVN transition days but they really should come as default – on unfamiliar systems I can’t believe how much of an impediment it is having to type the whole of git status each time.

I’ve only just switched from hub (which seems to be very nearly deprecated) to GitHub’s “official” command line tool. Hub’s browse command was pretty much the only thing I used and although gh also comes with its own browse command my muscle memory is just too ingrained to be able to switch. Fortunately adding a preceding ! will execute the alias as an external shell command so now I can type git browse and it will run gh browse for me. It’s not me it’s you.

Focus and deep work are an imperative to achieving quality and continual progress but sometimes reality hits and you find yourself working across many branches at the same time. Now what was the name of that branch I was working on the other day 🤔 This is an example of a feature that’s already part of git but only if you know the magic incantation – it’s git branch --sort=-committerdate or git recent with this alias.

I use git touch more than I should admit but something in me needs the commit’s date to represent the real date I finished the commit (even though squash and merge will have its way eventually). FYI you can pass any date and use --amend for evil 😈 “Yes I really was working late last night” git commit --amend --date=2023-01-23T23:34:51 --no-edit 😴

One more bonus alias that’s useful but I rarely use:

[alias]
  graph = log --oneline --graph

This is less of a graph nowadays when everything’s squashed and merged 😞 but I find being able to visually navigate the git tree really useful. Again this is already a part of git if you can remember where to find it but with an alias it’s a single tab-completable command away. The nice thing with all of these is that you can pass further options and they’re appended to the alias, so with this you can include all local branches with git graph --all or all remote branches with git graph --remotes (again tab completion came to my rescue – even through the alias – because I didn’t remember if it was --remote singular).