Git global config with multi user email support

If you work with multiple account/email for multiple client, you can have a structure like this for yours projects :


Git provide a global config file or a per repo config file, to set different email per project you can do for each project :

$ cd ~/code/client1/project11
$ git config user.name Frédéric Husson
$ git config user.email fhu@client1.com

But if you want to do it only once per client, you can use conditional includes

Set a global config ~/.gitconfig

    name = Frédéric Husson
    email = fhusson@mysecretpersonnaldomain.net

[includeIf "gitdir:~/code/client1/"]
    path = ~/code/client1/.gitconfig

[includeIf "gitdir:~/code/client2/"]
    path = ~/code/client2/.gitconfig

Then create specific config ~/code/client1/.gitconfig per client/folder

    email = fhu@client1.com

You can use this trick for others git config keys.

source : Stackoverflow - Different .gitconfig for a given subdirectory?

Discuss on Twitter