How to specify multiple user.name and user.email for different git remotes?

Viewed 3246

I have a repository in my local machine. This repository has 2 git remotes. Remotes A and B.

  • Remote A requires user.name X and user.email Y.
  • Remote B requires user.name Z and user.email W.

Can this be achieved in git? If so, how?

3 Answers

Say you have an account in gitlab with user name usergitlab with emails email@1, email@2, ... And that you also have an account in github with user name usergithub with emails email@2, email@3, ...

If your repo has a remote with two different urls, one for github:org/repo, another for gitlab:org/repo, and your local git email is email@2, then the name of the commit's author depends on the name of the user in gitlab and in github, that is, usergitlab and usergithub respectively.

Related