Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Pushing to two repos in one command

Tags:

git

I want to do git push origin and git push my_other_remote in the same line. Possible?

like image 403
Ram Rachum Avatar asked Apr 11 '11 11:04

Ram Rachum


People also ask

Can we have multiple origins in git?

You can have as many remotes as you want, but you can only have one remote named "origin". The remote called "origin" is not special in any way, except that it is the default remote created by Git when you clone an existing repository.

How do I push multiple branches to a remote?

git push origin will push from all tracking branches up to the remote by default. git push origin my-new-branch will push just your new branch.


2 Answers

You can get the same effect by adding an extra push URL for your origin remote. For example, if the URLs of your existing remotes are as follows:

$ git remote -v origin  me@original:something.git (fetch) origin  me@original:something.git (push) my_other_remote git://somewhere/something.git (fetch) my_other_remote git://somewhere/something.git (push) 

You could do:

 git remote set-url --add --push origin git://somewhere/something.git 

Then, git push origin will push to both repositories. You might want to set up a new remote called both for this, however, to avoid confusion. For example:

 git remote add both me@original:something.git  git remote set-url --add --push both me@original:something.git  git remote set-url --add --push both git://somewhere/something.git 

... then:

 git push both 

... will try to push to both repositories.

like image 192
Mark Longair Avatar answered Sep 19 '22 21:09

Mark Longair


You can put the following in the .git/config file:

[remote "both"]     url = url/to/first/remote     url = url/to/other/remote 

You can now push to both urls using git push both.

If you also want to fetch from them (useful for sync) you may add the following lines in your .git/config file:

[remotes]     both = origin, other 

Now you can also run git fetch both.

like image 38
Olivier Verdier Avatar answered Sep 19 '22 21:09

Olivier Verdier