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

Estimated 1 minute read · Wednesday, 19 January 2022

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.

~/path/to/work/directory/.gitconfig
Copy
# any customization/overrides can be added here
[user]
        name = Clarice Bouwer
        email = clarice@example.com
        ```
~/.gitconfig
Copy
[includeIf "gitdir:~/path/to/work/directory/"]
    path = ~/path/to/work/directory/.gitconfig
Copy
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
We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience and analyze website traffic. By clicking 'Accept', you agree to our website's cookie use as described in our Privacy Policy.