Directory-specific Git email address

Oct 16, 2025

This is how I set up Git to use my university email address for commits to university-related repositories.

In my global Git configuration file, I set my default identity and add an includeIf section to apply the configuration file specified in path to all the repositories in the ~/repos/uni/ directory:

[user]
    name = Cristina Leon
    email = user@personal.com
[includeIf "gitdir:~/repos/uni/"]
    path = ~/repos/uni/.gitconfig

Then, in the ~/repos/uni/.gitconfig file, I specify the name and email I use for university work:

[user]
    name = <my full name>
    email = me@uni-random.de

This way, all the repositories in the ~/repos/uni/ directory use my university email address, while all others use my default identity. This method can also be used to overwrite other global settings.

References