Push to Multiple Git Repos (Posted on December 22nd, 2012)

Here's a cool little trick I 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.

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "heroku"]
        url = [email protected]:maxburstein.git
        fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "github"]
        url = [email protected]:mburst/burstolio.git
        fetch = +refs/heads/*:refs/remotes/github/*
[remote "origin"]
        url = [email protected]:maxburstein.git
        url = [email protected]:mburst/burstolio.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.

Tags: Git

Comments:

  • Lucas - 2 years, 4 months ago

    I "figured this out" recently. I stopped using it because pushing to "origin" won't update your remote head for "heroku" and "github". Having some semantic-client-side connections for this could be tricky, so I've just learned to avoid it. (But if you need to do multiple pushed often, and know enough about git to handle the caveats, this works well.)

    reply

  • nsf - 2 years, 4 months ago

    I just do this: [alias] pub = "!git push pubgit && git push github"

    reply

  • Gergely Polonkai - 2 years, 4 months ago

    Why modify the config directly if git can do it for you? $ git remote add heroku [email protected]:maxburstein.git $ git remote add github [email protected]:mburst/burstolio.git

    reply

  • Max Burstein - 2 years, 4 months ago

    That will work perfectly for setting up the heroku and github branch. However, for pushing to both of them I needed to add a 3rd branch manually that I called origin. If you try to git remote add a url to a branch that already exists it will throw back "fatal: remote heroku already exists". So to get around that I just went ahead and did it manually.

    reply

  • education news - 1 week, 4 days ago

    Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.

    reply

  • hack hay day - 5 days, 20 hours ago

    The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

    reply

  • 8 ball pool cheat - 5 days, 20 hours ago

    Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

    reply

  • walkfit in stores - 1 day, 20 hours ago

    Thank you so much for sharing this great blog.Very inspiring and helpful too.Hope you continue to share more of your ideas.I will definitely love to read.

    reply