If you use Git for private projects and for university or work, you probably know this problem: every server expects a different email address. I push my private projects to GitHub with my private address, but my university, ZHAW, runs a GitHub Enterprise Server at github.zhaw.ch that only accepts my student email.
Setting user.email in every single repository works, until you forget it once. In this guide, we'll configure Git so it picks the right email automatically, based on the remote URL of the repository.
1. Check Your Git Version
The feature we’re going to use, conditional includes with hasconfig:remote.*.url, was added in Git 2.36. So first check your version:
git --version
Update or initially install it with:
brew install git
2. Set Your Default Email
Make your private email the global default. Git uses it for every repository that doesn’t match a special rule:
git config --global user.name "Your Name" git config --global user.email "your.name@email.com"
3. Create a Config File for the Enterprise Server
Next, create a second config file that only contains the settings for your enterprise server. This command creates ~/.gitconfig-enterprise (the name doesn’t matter) and writes your work email into it:
git config --file ~/.gitconfig-enterprise user.email "your.name@work.com"
The file now looks like this:
[user] email = your.name@work.com
4.
…
























