I use Git in both my personal and professional life. Depending on the context, I want to use different contact information. This is how I set this up on my machine.
My Work Git Config
I have a directory for my work at
~/work/ which contains my work specific Git config (
~/work/.gitconfig). It contains
[user] email = email@example.com
My Global Git Config
In my global Git config (
~/.gitconfig) I have the following.
[user] email = firstname.lastname@example.org name = Sal Ferrarello [includeIf "gitdir:~/work/**"] path = ~/work/.gitconfig
The first part of my global Git config contains my global (personal) user information but the second part (
includeIf "gitdir:~/work/") is where the magic happens.
This is a Git config conditional include, which loads my
~/work/.gitconfig anytime my current directory matches the pattern
~/work/** (i.e. whenever we are in
~/work or a sub-directory of
The result is if I create a Git commit inside the
~/work/ directory my
email@example.com email address is used but in other directories my
firstname.lastname@example.org email address is used.