Both GitLab and GitHub allow you to use a private email address.

Setting your commit email address on GitHub

Commit email on GitLab

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 'Your Name Here'
git config --global ''

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 'Different User Name'
git ''

Or you can use conditional includes in your global ~/.gitconfig file:

  name = Jane Doe
  email =

[includeIf "gitdir:~/gitlab/"]
  path = ~/gitlab/.gitconfig

Set local variables in ~/gitlab/.gitconfig:

  email =

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?