Machine-specific Git config changes

I store my .gitconfig in Git, naturally. It contains this block:

[user]
        email = will@willthompson.co.uk
        name = Will Thompson

which is fine until I want to use a different email address for all commits on my work machine, without needing git config user.email in every working copy. In the past I’ve just made a local branch of the config, merging and cherry-picking as needed to keep in sync with the master version, but I noticed that Git reads four different config files, in this order, with later entries overriding earlier entries:

  1. /etc/gitconfig – system-wide stuff, doesn’t help on multi-user machines
  2. $XDG_CONFIG_HOME/git/config (aka ~/.config/git/config) – news to me!
  3. ~/.gitconfig
  4. $GIT_DIR/config – per-repo, irrelevant here

So here’s the trick: put the standard config file at ~/.config/git/config, and then override the email address in ~/.gitconfig:

[user]
        email = wjt@endlessm.com

Ta-dah! Machine-specific Git config overrides. The spanner in the works is that git config --global always updates ~/.gitconfig if it exists, but it’s a start.

Some Git aliases.

Xavier suggested I blog my Git aliases.

[alias]
	ci = commit -v
	prune-all = !git remote | xargs -n 1 git remote prune
	record = !git add -p && git ci
	amend-record = !git add -p && git ci --amend
	stoat = !toilet -f future STOATS
	update-master = !git checkout master && git pull -r
	lol = log --graph --decorate --pretty=oneline --abbrev-commit
	lola = log --graph --decorate --pretty=oneline --abbrev-commit --all

Mostly1 self-explanatory.

git ci
Shorter than git commit, and -v shows you what you’re about to commit.
git prune-all
From the Git wiki.
git record; git amend-record
I started using these as a Darcs refugee, but they’re also a good way to avoid doing git add -p && git commit -a through overly-active muscle memory. I could probably simplify them to use git commit -p.
git lol; git lola
…come from Conrad Parker.

What’re your favourites?

  1. No, I don’t remember why I added git stoat either. []