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:
work and play.gitconfig which will include the correct config based on the current directoryHere are the steps needed to acomplish this:
Create the directories for the two accounts:
mkdir -p ~/work ~/play
.gitconfigCreate a file named ~/.gitconfig with the following content:
[includeIf "gitdir:~/play/"]
path = ~/.gitconfig-play
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
For play account(~/.gitconfig-play):
[user]
name = play_user
email = play_email
For work account(~/.gitconfig-work):
[user]
name = work_user
email = work_email
You can test it like this:
play:cd ~/play
mkdir test
git init
git config -l
This should output the configuration from the ~/.gitconfig-play file.
work:cd ~/work
mkdir test
git init
git config -l
This should output the configuration from the ~/.gitconfig-work file.