1

Provided there are two remote repositories (A, B) and there is a branch master (among others). The first repository A has all branches and the other one B has to have one only masterB.

How can I push local branch master to both remote repositories with a single "git push" command ? (mapping A: master->master; mapping B: master->masterB)


tried so far:

[remote "A"]
    url = <urlA>
    fetch = +refs/heads/*:refs/remotes/A/*
[remote "B"]
    url = <urlB>
    fetch = +refs/heads/*:refs/remotes/B/*
    push = master:masterB
[branch "master"]
    remote = A
    merge = refs/heads/master
    pushRemote = A
    pushRemote = B //this overrides the previous push remote; how can I use both ?

The reference says that multiple 'pushRemote' entries are possible.

dajuric
  • 2,373
  • 2
  • 20
  • 43
  • Could you tell us what you are using this for? If it's for deployment, there are better ways to handle deployment. – Schwern Jul 21 '18 at 01:08

1 Answers1

1

Your tutorial does mention:

Then git allows branches to have multiple branch.<name>.pushRemote entries.
You must edit the .git/config file to set them.

That is not apparent from git config branch.<name>.pushRemote

When on branch , it overrides branch.<name>.remote for pushing.
It also overrides remote.pushDefault for pushing from branch <name>.

When you pull from one place (e.g. your upstream) and push to another place (e.g. your own publishing repository), you would want to set remote.pushDefault to specify the remote to push to for all branches, and use this option to override it for a specific branch.

So managing that case with a script would be easier than tweaking git config settings.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for the answer. I had tackled this with a script, but I was hoping I can achieve this via config so I can use e.g. Visual Studio built-in git support and not to worry about running the script later. Can you give me an example what should I change in the config above to achieve this ? – dajuric Jul 21 '18 at 19:12
  • @dajuric You can try https://stackoverflow.com/a/14290145/6309: this is not specific to *one* branch but could still help. – VonC Jul 21 '18 at 19:39
  • Thanks. Seen that; does not allow renaming a branch for another remote-repo. I have upvoted your answer. Many thanks! – dajuric Jul 21 '18 at 21:40