8

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?

Abel Callejo
  • 11,749
  • 8
  • 60
  • 74
  • 2
    Make two repositories for the two remotes. Config `user.name` and `user.email` with `git config --local` in each repository. `user.name` and `user.email` have nothing to do with a remote. – ElpieKay Jul 14 '17 at 01:54
  • how about you have different username and email of your bitbucket and github accounts? you can't use them both at the same time as remote repositories? – Abel Callejo Jul 14 '17 at 06:42
  • `user.name` and `user.email` have nothing with remotes. They are only used to put commiter's name/email in commits, that's all. If you want to have different authorization for different remotes you can create different ssh keys and configure ssh to use each key for a different remote host. – phd Jul 14 '17 at 13:25

2 Answers2

2

With Git 2.13, you now have conditional include for git config, but it is only based on filesystem path of the repository.

So you still need two different copies of the same repo. You can achieve that with git worktree (one clone, multiple working tree)

You can then modify your global config spec to include a local config with a specific set of user.name/user.email depending on your current folder.
See "Using different Git emails" from pltvs (Alex Pliutau)

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
0

I think you can achieve by doing something like this by using --local instead of --global

A git config user.email Y git config user.name "X"

B git config user.email W git config user.name "Z"

The values stored in the .git/config for particular repo than the global configuration file.

ntshetty
  • 1,150
  • 8
  • 20
  • does that mean if I have to push to remote **A** I have to do `git config` then do another `git config` before pushing to remote **B**? – Abel Callejo Jul 14 '17 at 05:15