Push to Multiple Git Repositories

Push to Multiple Git Repositories

Here’s a cool little trick I’ve found out about the other day. Even though Git is a distributed revision control system, there are times when you need to push to two systems at once. In my case those systems are Github and Heroku. Here is a simple way to do it by modifying your .git/config file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "heroku"]
  url = git@heroku.com:pgsearch.git
  fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "github"]
  url = git@github.com:Bunlong/rvm.git
  fetch = +refs/heads/*:refs/remotes/github/*
[remote "origin"]
  url = git@heroku.com:pgsearch.git
  url = git@github.com:Bunlong/rvm.git

The “heroku” and “github” remotes are generated by git and are created in the setup instructional steps of each service respectively. I went ahead and manually added the remote “origin” and just copied the url variable from the other remotes. You’ll now be able to push to both by calling “git push origin” and then you can fetch from each one as individually needed.

So far so good, That’s it!!! See ya!!! :)