Many developers have one laptop that they use for both professional as well as private projects. If these projects are managed with git, it might be nice to use different author names or e-mail addresses when committing. When I am at work, I would like my work e-mail address to show up whereas my private open source or community projects should use my personal address.

Fortunately, git makes it really easy to set up different configurations that take into account the folder that you are currently working in. In your ~/.gitconfig you can use [includeIf "gitdir:<path>"] to tell git to load a second configuration file if you are working within the given <path>.

[user]
  name = Knut Hühne
  email = knut@k-nut.eu
[includeIf "gitdir:~/work/"]
  path = .gitconfig-work

Where .gitconfig-work could for example contain this:

[user]
  email = knut.huehne@futurice.com
  signingkey = 1234ABCD

Here I am telling git to change my e-mail address and to also sign my commits with the given gpg key when I am in any subfolder of ~/work. Settings that are not overridden are inherited from the main ~/.gitconfig. This means that my name will be the same in both cases.

Of course, you are not limited to the [user] section here. You could for example also tell git to use other aliases or maybe another pull strategy when you are in the given directory. Changing your name or your e-mail is probably the most common use-case though.

Do you have any other creative ideas where this could be useful? Let me know on twitter.