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

- 84,019
- 84
- 236
- 374
-
1I don't think you can do this using the standard commands but you could write a `git-multipush` or something and use that. – Noufal Ibrahim Apr 11 '11 at 11:26
-
1Possible duplicate of [pull/push from multiple remote locations](http://stackoverflow.com/questions/849308/pull-push-from-multiple-remote-locations) – techraf Aug 20 '16 at 00:30
-
1Possible duplicate of [Able to push to all git remotes with the one command?](https://stackoverflow.com/questions/5785549/able-to-push-to-all-git-remotes-with-the-one-command) – Dave Everitt May 15 '19 at 16:26
4 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.

- 352
- 2
- 7

- 446,582
- 72
- 411
- 327
-
Does this also update the `remote/origin` and `remote/my_other_remote` tracking branches? – Paŭlo Ebermann Apr 11 '11 at 12:02
-
@Paŭlo Ebermann: my (very brief) testing suggests that `refs/remotes/origin/master` and `refs/remotes/my_other_remote/master` will be both be updated in the situation where the URLs of both are added as push URLs to `origin` and you do `git push origin`. – Mark Longair Apr 11 '11 at 13:21
-
1this looks probably like what I am looking for, but I am still a bit confuse... How to proceed, if I wanna commit my app to Heroku and also to BitBucket? Firstly I have to create to repo and comiting to Heroku and then with the same way to create a repo on BitBucket, or what's the right way? – user984621 Mar 04 '12 at 10:33
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
.

- 46,998
- 29
- 98
- 90
-
8is the solution you offer fundamentally the same as Mark's one (except you do it via manual editing), or is there any other difference ? – Stéphane Gourichon Apr 29 '15 at 15:22
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.

- 3,662
- 11
- 48
- 73
In recent versions of Git you can add multiple pushurls for a given remote. Use the following to add two pushurls to your origin:
git remote set-url --add --push origin git://original/repo.git
git remote set-url --add --push origin git://another/repo.git
So when you push to origin, it will push to both repositories.
UPDATE 1: Git 1.8.0.1 and 1.8.1 (and possibly other versions) seem to have a bug that causes --add to replace the original URL the first time you use it, so you need to re-add the original URL using the same command. Doing git remote -v should reveal the current URLs for each remote.
UPDATE 2: Junio C. Hamano, the Git maintainer, explained it's how it was designed. Doing git remote set-url --add --push <remote_name> adds a pushurl for a given remote, which overrides the default URL for pushes. However, you may add multiple pushurls for a given remote, which then allows you to push to multiple remotes using a single git push. You can verify this behavior below:
$ git clone git://original/repo.git
$ git remote -v
origin git://original/repo.git (fetch)
origin git://original/repo.git (push)
$ git config -l | grep '^remote\.'
remote.origin.url=git://original/repo.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
Now, if you want to push to two or more repositories using a single command, you may create a new remote named all (as suggested by @Adam Nelson in comments), or keep using the origin, though the latter name is less descriptive for this purpose. If you still want to use origin, skip the following step, and use origin instead of all in all other steps.
So let's add a new remote called all that we'll reference later when pushing to multiple repositories:
$ git remote add all git://original/repo.git
$ git remote -v
all git://original/repo.git (fetch) <-- ADDED
all git://original/repo.git (push) <-- ADDED
origin git://original/repo.git (fetch)
origin git://original/repo.git (push)
$ git config -l | grep '^remote\.all'
remote.all.url=git://original/repo.git <-- ADDED
remote.all.fetch=+refs/heads/*:refs/remotes/all/* <-- ADDED
Then let's add a pushurl to the all remote, pointing to another repository:
$ git remote set-url --add --push all git://another/repo.git
$ git remote -v
all git://original/repo.git (fetch)
all git://another/repo.git (push) <-- CHANGED
origin git://original/repo.git (fetch)
origin git://original/repo.git (push)
$ git config -l | grep '^remote\.all'
remote.all.url=git://original/repo.git
remote.all.fetch=+refs/heads/*:refs/remotes/all/*
remote.all.pushurl=git://another/repo.git <-- ADDED
Here git remote -v shows the new pushurl for push, so if you do git push all master, it will push the master branch to git://another/repo.git only. This shows how pushurl overrides the default url (remote.all.url).
Now let's add another pushurl pointing to the original repository:
$ git remote set-url --add --push all git://original/repo.git
$ git remote -v
all git://original/repo.git (fetch)
all git://another/repo.git (push)
all git://original/repo.git (push) <-- ADDED
origin git://original/repo.git (fetch)
origin git://original/repo.git (push)
$ git config -l | grep '^remote\.all'
remote.all.url=git://original/repo.git
remote.all.fetch=+refs/heads/*:refs/remotes/all/*
remote.all.pushurl=git://another/repo.git
remote.all.pushurl=git://original/repo.git <-- ADDED
You see both pushurls we added are kept. Now a single git push all master will push the master branch to both git://another/repo.git and git://original/repo.git.
IMPORTANT NOTE: If your remotes have distinct rules (hooks) to accept/reject a push, one remote may accept it while the other doesn't. Therefore, if you want them to have the exact same history, you'll need to fix your commits locally to make them acceptable by both remotes and push again, or you might end up in a situation where you can only fix it by rewriting history (using push -f), and that could cause problems for people that have already pulled your previous changes from the repo.

- 588
- 8
- 13