How to Configure Your Work Email Address for All Git Work Projects
I did it again! I checked out a new git project for work, made a change, and realized only later that the commit includes my personal email address instead of my work email address. 😢
The problem is that I configured my personal email address as the global
default git config --global user.email "mpv@personal.com"
and have been
trying to remember to configure each work repo with my work email address
git config user.email "mpv@work.com"
.
Clearly this is not working because I forget to do it every single time I clone a new work repo.
Luckily I found a great solution today. In your ~/.gitconfig
file you can
conditionally include
another config file based on the path of the git repo. This allows you
configure an email address for all repos under a given directory.
As an example, with the below configuration, any git repo under ~/work
will
use the email address mpv@work.com
. Hope this helps you.
# ~/.gitconfig
[user]
name = Michael Vosseller
email = mpv@personal.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
~/
# ~/work/.gitconfig
[user]
email = mpv@work.com