For some reason, there aren’t enough guides for collaboration on Heroku. There is a quickstart guide over at the Heroku docs for cases when both source hosting and deploys happen through a single repository on Heroku. It does not cover other scenarios though.
This is mostly on Git, which Heroku uses for source control and deploy triggers. This also assumes that the heroku gem is all installed and set up.
Separate Source Hosting
Starting off with the most common scenario: Your source is hosted somewhere else (GitHub, for example) and you deploy on Heroku.
If you have not done so yet, clone your application:
$ git clone git@github.com:me/myapp.git myapp
Besides making a copy of the code in the myapp directory, this also takes care of adding the repository as the default remote "origin". This means that, by default, doing:
$ git push
from the directory would already be equivalent to doing:
$ git push origin
which should push your changes up to the source host.
Next let us add the repository on Heroku as a different remote:
$ cd myapp
$ git remote add heroku git@heroku.com:myapp.git
$ git fetch heroku # Download objects and refs
At this point, you should be able to start deploying with:
$ git push heroku
and run heroku gem commands like such:
$ heroku console
$ heroku info
Multiple Environments
Elijah Miller wrote a great guide Deploying Multiple Environments on Heroku. If you are looking into setting up the multiple environments, head to that article instead. The rest of this section is for collaborating on already set up application environments.
So let us say we want to work with the following scenario:
| Role |
Heroku |
Git Repository |
| Source |
- |
git://github.com/me/myapp.git |
| Production |
myapp |
git://heroku.com/myapp.git |
| Staging |
myapp-staging |
git://heroku.com/myapp-staging.git |
The procedure is pretty much the same as above. First, you need to clone your source repository:
$ git clone git@github.com:me/myapp.git myapp
The next step is adding the Heroku repositories as remotes. You will have to come up with remote names better than “heroku” since you will be working with more than one Heroku application this time. The most obvious decent naming scheme is, of course, naming them after the environments:
$ cd myapp
$ git remote add production git://heroku.com/myapp.git
$ git remote add staging git://heroku.com/myapp-staging.git
$ git fetch production # Download objects and refs
$ git fetch staging # Download objects and refs
Since the source repository has been added as the “origin” remote, pushing changes for regular updates even pre-deploy would still be as simple as:
$ git push
Deploying is also straightforward:
$ git push production production-branch-name:master
$ git push staging staging-branch-name:master
Since there will be more than one Heroku repository in your Git configuration, the heroku gem will not be able to automatically determine the application you want to run application commands for. You will need to specify the application name like this:
$ heroku console --app myapp
$ heroku rake db:migrate --app myapp-staging