Manage your double life on Git!

Are you coding for work and personal projects on the same computer? Then you probably find yourself regularly committing with your personal email address on your professional projects, and vice versa.

And it’s annoying, isn’t it? Constantly having to rewrite the history on one side, the other side, with commits that are already finalized on a protected main branch, etc.

Git Logo

It’s time to put an end to this! I propose that you better configure your Git environments. For that, there are two possible approaches.

1. Repository by repository

This is, of course, the technique that provides the finest granularity. You can override the global Git settings project by project using the following commands to be executed at the root of each project:

git config "Pro Name"
git config ""

2. Directory by directory

This time, the goal is to separate your projects more drastically to save precious time:

  • In your global configuration (probably ~/.gitconfig), enter the 'name' and 'email' that you are most likely to use as a priority, let’s say your professional information.

  • Add the following 2 lines after this information to conditionally override them (here, only if you are in the ~/Personal directory):

    [includeIf "gitdir:~/Personal/"]
    path = ~/Personal/.gitconfig
  • In ~/Personal, add a .gitconfig file that will contain your personal information this time.

  • When you work in the ~/Personal folder, your commits will automatically have your personal information. No more headaches!

What about projects that already have mixed commits?

And if, despite everything, you have repositories that mix commits with your professional and personal information, you can always use the technique I described in this article to clean up!