DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

How to use a different email address in Git in sub directories

Motivation

I want to override my personal email address I use for Git with my work email address in my work directory without manually changing it each time.

Create a config file in the work directory

touch ~/path/to/work/directory/.gitconfig 
Enter fullscreen mode Exit fullscreen mode
# any customization/overrides can be added here [user] name = Clarice Bouwer email = clarice@example.com 
Enter fullscreen mode Exit fullscreen mode

Update ~/.gitconfig

[includeIf "gitdir:~/path/to/work/directory/"] path = ~/path/to/work/directory/.gitconfig 
Enter fullscreen mode Exit fullscreen mode

Verify

cd ~/ git config user.email # should be your default config email cd ~/path/to/work/directory git config user.email # should be your override email 
Enter fullscreen mode Exit fullscreen mode

Based on Stack Overflow: Set Git config values for all child folders and Alvin Alexander: Git show change username and email address.

Top comments (1)

Collapse
 
kopseng profile image
Carl-Erik Kopseng

This works great. Been using something similar for a while