Last Updated: November 27, 2020
·
602
· alexvpopov

How to use your personal email for personal projects and company email for company projects

Most companies require their employees to use their company email when working on company projects. At the same time, most people prefer to use their personal email for projects they work on in their free time. If one puts their personal email in ~/.gitconfig, they'll have to change this setting for every company project they work on or vice versa. This is annoying. Here's how to make Git always pick the right email:

  • Put your personal email in ~/.gitconfig:
[user]
  name = Your Name
  email = your@email.com
  • Inside your root directory, create a directory for all your company's projects:
mkdir ~/ACME
  • Inside it, create another .gitconfig file and add your company email there:
touch ~/ACME/.gitconfig

and

[user]
  email = your.name@acme.com
  • At the end of ~/.gitconfig add:
[includeIf "gitdir:~/ACME/"]
  path = ~/ACME/.gitconfig

From now on, any project inside ~/ACME will use your.name@acme.com and projects in other directories - your@email.com.