Both GitLab and GitHub allow you to use a private email address.
Setting your commit email address on GitHub
Now, your regular email address will be private and others can’t see it on those platforms.
But that also means that you now have two different email addresses that you have to add to your Git configuration.
There are different ways to tackle this problem.
For example, you can set a global configuration:
git config --global user.name 'Your Name Here'
git config --global user.email 'your@email.here'
And then set a local configuration for each repository on your machine. Navigate to the root folder of your project and run these commands:
git config user.name 'Different User Name'
git config.user.email 'different@user.email'
Or you can use conditional includes in your global ~/.gitconfig
file:
[user]
name = Jane Doe
email = jane@doe.com
[includeIf "gitdir:~/gitlab/"]
path = ~/gitlab/.gitconfig
Set local variables in ~/gitlab/.gitconfig
:
[user]
email = janesemail@gitlab.com
These solutions work on a “per repo” basis and don’t check the remote repository domain (GitLab or GitHub).
Please check the original StackOverflow question for more details: Can I specify multiple users for myself in .gitconfig?