Directory-specific Git email address
October 16, 2025
This solution allows Git identities to be separated across different work areas. For example, I use it to separate my personal projects from my university projects.
First, set a default identity in the global Git configuration
file. Then,
add an includeIf section to apply the configuration file specified in path
to all repositories in ~/repos/uni/:
[user]
name = Jane Doe
email = personal@example.com
[includeIf "gitdir:~/repos/uni/"]
path = ~/repos/uni/.gitconfig
In the specified path file, set the new Git identity:
[user]
name = Jane Doe
email = uni@example.com
Now all repositories in ~/repos/uni/ use the university email address, while
others use the default identity.