6

I have a local repository that i want to push to multiple remote repositories (firstremote, secondremote). This can simply be done by editing .git/config and creating a new remote with multiple urls.

But additionally I want to push my local branch to different-named remote branches. E.g. push (mybranch) to a branch named firstbranch on firstremote and to secondbranch on secondremote.

For this I have no idea how to specify the different upstream branch names.

Note: I'd like to do the push automatically with a single git push.

ejoerns
  • 965
  • 2
  • 11
  • 22
  • http://stackoverflow.com/questions/520650/how-do-you-make-an-existing-git-branch-track-a-remote-branch?rq=1 – Daniel Hilgarth Aug 09 '13 at 10:55
  • I know how to use it for a single upstream, but not how to set multiple for same branch – ejoerns Aug 09 '13 at 11:04
  • 2
    Just make an alias that pushes to multiple remotes. –  Aug 09 '13 at 14:10
  • 1
    Yes, I think that's the best hint so far. Added alias `push-all = !git push firstremote mybranch:firstbranch && git push secondremote mybranch:secondbranch` to projects git config. So I also used @mahead's one-liner ;). – ejoerns Aug 09 '13 at 14:33

1 Answers1

3

Use colons! As per git-push doc:

The format of a parameter is an optional plus +, followed by the source ref , followed by a colon :, followed by the destination ref . It is used to specify with what object the ref in the remote repository is to be updated. If not specified, the behavior of the command is controlled by the push.default configuration variable.

The is often the name of the branch you would want to push, but it can be any arbitrary "SHA-1 expression", such as master~4 or HEAD (see gitrevisions(7)).

The tells which ref on the remote side is updated with this push. Arbitrary expressions cannot be used here, an actual ref must be named. If : is omitted, the same ref as will be updated.

So, this should do the trick:

git push firstremote mybranch:firstbranch
git push secodremote mybranch:secondbranch
madhead
  • 31,729
  • 16
  • 153
  • 201
  • Yes, I know this syntax. Maybe I didn't mention that explicitly but I would prefer to use a single push command with as less options as possible to simplify work flow. Isn't that possible? – ejoerns Aug 09 '13 at 13:13
  • 1
    One push is for one remote. [A remote can have multiple URLs](http://stackoverflow.com/a/4255934/750510), thus you can push to multiple urls with one command, but it does not solve the problem of naming the branches and IMHO this is not worth the trouble. – madhead Aug 09 '13 at 13:17
  • Yes, that's what I mentioned in my question. Then I have to do it manually or write a 2-liner ;) Thanks so far – ejoerns Aug 09 '13 at 13:35
  • 2
    You can write it in one line! `git push firstremote mybranch:firstbranch && git push secodremote mybranch:secondbranch` – madhead Aug 09 '13 at 13:37