41

Basically I wanted to do something like git push mybranch to repo1, repo2, repo3

right now I'm just typing push many times, and if I'm in a hurry to the the pushing done, I just send them all to the background git push repo1 & git push repo2 &

I'm just wondering if git natively supports what I want to do, or if maybe there's a clever script out there, or maybe a way to edit the local repo config file to say a branch should be pushed to multiple remotes.

kch
  • 77,385
  • 46
  • 136
  • 148

2 Answers2

79

You can have several URLs per remote in git, even though the git remote command did not appear to expose this last I checked. In .git/config, put something like this:

[remote "public"]
    url = git@github.com:kch/inheritable_templates.git
    url = kch@homeserver:projects/inheritable_templates.git

Now you can say “git push public” to push to both repos at once.

Aristotle Pagaltzis
  • 112,955
  • 23
  • 98
  • 97
  • 2
    Nice tip. Note, this only works for push. For fetch it seems to just use the first url entry. It also seems you can target a branch on this multi-remote. So you can just do "git pull" without the remote name if you add something like this to your config `[branch "master"] remote = public` – studgeek Mar 09 '12 at 06:50
9

What I do is have a single bare repository that lives in my home directory that I push to. The post-update hook in that repository then pushes or rsyncs to several other publicly visible locations.

Here is my hooks/post-update:

#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, make this file executable by "chmod +x post-update".

# Update static info that will be used by git clients accessing
# the git directory over HTTP rather than the git protocol.
git-update-server-info

# Copy git repository files to my web server for HTTP serving.
rsync -av --delete -e ssh /home/afranco/repositories/public/ afranco@slug.middlebury.edu:/srv/www/htdocs/git/

# Upload to github
git-push --mirror github 
Adam Franco
  • 81,148
  • 4
  • 36
  • 39
  • that's good. care to share or explain git-update-server-info? – kch Oct 03 '08 at 00:00
  • As I've added to the answer: git-update-server-info writes some static info files that will be used by git clients accessing the git directory over HTTP rather than the git protocol. See the following for more info: http://www.kernel.org/pub/software/scm/git/docs/git-update-server-info.html – Adam Franco Oct 03 '08 at 22:03