|home| |posts| |projects| |cv| |bookmarks| |github|

Multiple Git Configs on One Computer

There may be a situation where you have to work with two git accounts on the same computer, for example one for work and one for personal projects.

With one global .gitconfig this cannot be done.

But it can be done if you:

Here are the steps needed to acomplish this:

Create directories

Create the directories for the two accounts:

mkdir -p ~/work ~/play

Global .gitconfig

Create a file named ~/.gitconfig with the following content:

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

Individual configs

For play account(~/.gitconfig-play):

[user]
 name = play_user
 email = play_email

For work account(~/.gitconfig-work):

[user]
 name = work_user
 email = work_email

Test

You can test it like this:

cd ~/play
mkdir test
git init
git config -l

This should output the configuration from the ~/.gitconfig-play file.

cd ~/work
mkdir test
git init
git config -l

This should output the configuration from the ~/.gitconfig-work file.