DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

1 1

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
kopseng profile image
Carl-Erik Kopseng

This works great. Been using something similar for a while

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay