Multiple Accounts and Git

If you have multiple accounts to use with Git — such as a personal and a work account — you can have your Git Config (typically ~/.gitconfig) conditionally include other configs depending on the folder you’re working in. In those extra configs you then can override some settings.

Here’s an example ~/.gitconfig that has two dynamic includes:

  name = "John Doe"

[includeIf "gitdir:~/repos/personal/"]
  path = ~/.gitconfig.personal

[includeIf "gitdir:~/repos/work/"]
  path = ~/

Inside each ~/.gitconfig.XXX you can then list extra config values, here the email address to use for each:

  email =

💡 If you want to use individual SSH keys for each account, there’s some more steps you need to take.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.