- Published on
How to specify multiple users in .gitconfig
- Authors
- Name
- Gene Zhang
Support Multiple Users
Global config ~/.gitconfig
[user]
name = John Personal
email = john@gmail.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
Work specific config ~/work/.gitconfig
[user]
name = John Work
email = john.doe@company.tld
Test
Clone a repo into ~/work/test-repo
. Open the teminal and check the user email by:
% git config --get user.email
john.doe@company.tld
Multiple SSH access solution
If you are using SSH to access the repos, follow these steps to generate a new SSH key for the work accounts:
For example, if you have generated a new key named id_ed25519_work
, test it by running:
% ssh -i ~/.ssh/id_ed25519_work -o IdentitiesOnly=yes -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
Then append this section into ~/work/.gitconfig
:
[core]
sshCommand = ssh -i ~/.ssh/id_ed25519_work -o IdentitiesOnly=yes
Reference
https://stackoverflow.com/a/43654115
https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresshCommand