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.

4
  • stackoverflow.com/questions/520650/… Commented Aug 9, 2013 at 10:55
  • I know how to use it for a single upstream, but not how to set multiple for same branch Commented Aug 9, 2013 at 11:04
  • 2
    Just make an alias that pushes to multiple remotes. Commented Aug 9, 2013 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 ;). Commented Aug 9, 2013 at 14:33

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

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?
One push is for one remote. A remote can have multiple URLs, 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.
Yes, that's what I mentioned in my question. Then I have to do it manually or write a 2-liner ;) Thanks so far
You can write it in one line! git push firstremote mybranch:firstbranch && git push secodremote mybranch:secondbranch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.