Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push to different branches on multiple remotes

Tags:

git

branch

push

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.

like image 493
ejoerns Avatar asked Nov 02 '22 16:11

ejoerns


1 Answers

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`
like image 102
madhead - StandWithUkraine Avatar answered Nov 08 '22 03:11

madhead - StandWithUkraine