Managing Multiple Remotes with Git

On August 3, 2012, in Git, by Anuj Gakhar

Managing multiple remotes with Git is a pretty common thing, I would say. However, I never had the need to do it, until today. I think it’s a totally awesome thing that you can change code locally and push it to different remotes with one command and every one is happy.

Since my particular requirement was to deal with Heroku and Github in the same repository, that’s the context I will be talking about in this post. So, let’s say you have a Heroku app. With the Heroku CLI installed, it’s pretty straightforward to look at the remote information on your repo.

[xml]git remote -v[/xml]

That will give you something like this :-

[xml]origin git@heroku.com:YOUR_HEROKU_APP.git (fetch)
origin git@heroku.com:YOUR_HEROKU_APP.git (push)[/xml]

Now, since I wanted to use “origin” for the github repo, I decided to rename heroku’s origin to “heroku” – which makes sense I think.

[xml]git remote rename origin heroku[/xml]

So, that now allows me to add github’s repo as origin

[xml]git remote add origin git@github.com:YOUR_GITHUB_REPO.git[/xml]

And that’s it.

Now, I can push to heroku with [xml]git push heroku master[/xml]
and push to github with [xml]git push origin master[/xml]

I find that totally awesome!

Tagged with:  

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2011 Anuj Gakhar
%d bloggers like this: