Using Git Remotes to easily push your code to different Heroku apps

Published: by

This is a very short post to illustrate a git configuration that may help you to easily deploy your project into different heroku apps.

It is specially useful if you have different Heroku apps for each environment (QA, Staging, Production), allowing you to switch the target app(environment) by changing a single parameter on push command.

Here is how my .git/config file looks like:

...
[remote "heroku-qa"]
        url = https://git.heroku.com/project-qa.git
        fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "heroku-stg"]
        url = https://git.heroku.com/project-stg.git
        fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "heroku-prod"]
        url = https://git.heroku.com/project.git
        fetch = +refs/heads/*:refs/remotes/heroku/*
...

Note the multiple remote entries, each one of them is a git remote.

The only config here you'd need to change is the url, each url points to a different git repository associated with that Heroku "app"(under quotes because we have a single app in fact and just different environments)

And to use them:

git push heroku-qa master
git push heroku-stg master
git push heroku-prod master

As you noticed the first parameter to the push command is the remote and the second the branch you want to push.

So "origin" is just another remote ?

Exactly, origin is the default remote that gets added once you run git clone.