When working on a project on GitHub, I sometimes like to keep an additional copy floating around on my own server for esoterical reasons. While the following is possible:
$ git remote add origin git@a.b:c/d.git $ git remote add another git@w.x:y/z.git $ git push origin $ git push another
it is quite annoying to issue the push command twice — advanced git-fu to the resuce. Some dude over at Stack Overflow pointed out that Git supports the notion of a pushurl
, being an endpoint for pushing to a given remote. The fun thing is that every remote may have multiple push URLs, which is exactly what I needed.
It needs to be said that despite the usage of the --add
flag in the following snippet, a push URL always overwrites the default URL, so adding only one URL results in the original entry being overruled. So, for the situation given in the example above:
$ git remote add origin git@a.b:c/d.git $ git remote set-url --add --push origin git@a.b:c/d.git $ git remote set-url --add --push origin git@w.x:y/z.git $ git push origin
And that’s it. By pushing to origin
Git instead pushes to both registered URLs.