Push to Multiple Git Repos

Send to friend

If you’ve got a project with multiple git remotes, and you’d like to update both of them with a single operation, there’s an easy way to do it. Just edit your .git/config file to include a new target named “all”:

[remote "origin"]
  url = git@github.com:ffmike/BigOldRailsTemplate.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
[remote "codaset"]
  url = git@codaset.com:ffmike/bigoldrailstemplate.git
  fetch = +refs/heads/*:refs/remotes/codaset/*
[remote "all"]
  url = git@github.com:ffmike/BigOldRailsTemplate.git
  url = git@codaset.com:ffmike/bigoldrailstemplate.git

With this setup, pushes and pulls on my local master branch go to GitHub by default. But if I execute ‘git push all’ it updates both the GitHub repository and the Codaset repository. The one little annoyance is that master then thinks it’s ahead of the remote, but that’s easily remedied by executing a ‘git pull’ on it.

I’ve been using this in cases where I’m backing up a repo to a private Gitosis server as well as spreading public repos between multiple cloud services for easy backup.

Images: