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.

git remote -v

That will give you something like this :-

origin	git@heroku.com:YOUR_HEROKU_APP.git (fetch)
origin	git@heroku.com:YOUR_HEROKU_APP.git (push)

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.

git remote rename origin heroku

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

git remote add origin git@github.com:YOUR_GITHUB_REPO.git

And that’s it.

Now, I can push to heroku with

git push heroku master

and push to github with

git push origin master

I find that totally awesome!

Tagged with:  

Leave a Reply

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 292 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: