Git Configuration Multiple usernames and email address


Example

Since Git 2.13, multiple usernames and email addresses could be configured by using a folder filter.

Example for Windows:

.gitconfig

Edit: git config --global -e

Add:

[includeIf "gitdir:D:/work"]
  path = .gitconfig-work.config    

[includeIf "gitdir:D:/opensource/"]
  path = .gitconfig-opensource.config
Notes
  • The order is depended, the last one who matches "wins".
  • the / at the end is needed - e.g. "gitdir:D:/work" won't work.
  • the gitdir: prefix is required.

.gitconfig-work.config

File in the same directory as .gitconfig

[user]
  name = Money
  email = work@somewhere.com

.gitconfig-opensource.config

File in the same directory as .gitconfig

[user]
  name = Nice
  email = cool@opensource.stuff

Example for Linux

[includeIf "gitdir:~/work/"]
  path = .gitconfig-work
[includeIf "gitdir:~/opensource/"]
  path = .gitconfig-opensource

The file content and notes under section Windows.