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 = work-sal@example.com
My Global Git Config
In my global Git config (~/.gitconfig
) I have the following.
[user]
email = party-sal@example.com
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 ~/work
).
The result is if I create a Git commit inside the ~/work/
directory my work-sal@example.com
email address is used but in other directories my party-sal@example.com
email address is used.
Leave a Reply