Both GitLab and GitHub allow you to use a private email address.
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 'email@example.com'
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 'firstname.lastname@example.org'
Or you can use conditional includes in your global
[user] name = Jane Doe email = email@example.com [includeIf "gitdir:~/gitlab/"] path = ~/gitlab/.gitconfig
Set local variables in
[user] email = firstname.lastname@example.org
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?