Git: Pushing to two repos in one command

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


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.


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.