Git: Pushing to two repos in one command

Just a small addition to the excellent answers provided already - if you dont want to bother with adding "both" and just want to have all operations pushed to both repos automatically, just add your second repo as another url under origin in the git config.

[remote "origin"]
    url = someUrl.git
    url = secondUrl.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Now "git push" uses both.


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.


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.

Tags:

Git