~fhusson

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 :

~/code/client1/project11
~/code/client1/project12
~/code/client2/project21
~/code/client2/project22
~/code/personnal/project31
~/code/personnal/project32

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 [email protected]

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

Set a global config ~/.gitconfig

[user]
    name = Frédéric Husson
    email = [email protected]

[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

[user]
    email = [email protected]

You can use this trick for others git config keys.

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

Discuss on Twitter