This is a guide to setting up the Heroku toolset so that you can deploy an existing Heroku app, or create a new app on Heroku.
As you may not yet know, the vanilla Heroku toolset can only work with a single Heroku account. This is fine for personal use, or maybe for minor startups, but as soon as you have to simultaneously manage and deploy Heroku applications that belong to several accounts this becomes a huge inconvenience. Fortunately there is a way to make deployment simple again.
- Download the Heroku Toolbelt – this is the recommended way to install Heroku utilities.
- Install the heroku-accounts plugin – this will let you use multiple Heroku accounts in parallel.
heroku plugins:install git://github.com/ddollar/heroku-accounts.git
- Now you can login to your account.
heroku accounts:add [account_name] --auto
Replace [account_name] with any name that’s meaningful to you, the name is only used locally.
Be prepared to enter the credentials to the Heroku account.
After logging in, heroku-accounts will automatically generate an SSH key (you cannot reuse the same key for two Heroku accounts), store it at
~/.ssh/identity.heroku.[account_name], upload the public key to Heroku and create a
heroku.[account_name]host record in your ssh-config that would use the correct key. Neat, huh?
- Go to the project folder. Time to enable deployment.
heroku git:remote --app [app_name] heroku accounts:set [account_name]
[app_name]is the public name of the Heroku app (its URL would be
These commands add a
herokugit remote that will be used for deployment. The entire configuration is stored in
- Deploy away!
git push heroku master
If the app has not yet been deployed, instead of the step 4 you’d have to create the app:
heroku accounts:set [account_name] heroku apps:create [app_name] heroku accounts:set [account_name]
heroku accounts:set is needed to point the git remote URL to the hostname configured in the step 3.
- If you have to deploy the same code into two Heroku apps, like staging and production, just add two git remotes, like heroku-staging and heroku-production and you’ll be able to deploy to any of them. However, when running Heroku commands you’d have to specify the app on the command line, such as:
heroku run rake db:setup --app myapp-staging
- If you’d like to deploy a different branch (which is risky, but useful for staging), do
git push --force heroku branch_name:master
Remember, just pushing the branch to Heroku will do nothing, it has to be pointed at by
- If you have to deploy the same code into two Heroku accounts, you can still do that with two remotes, but to run Heroku commands you will have to specify the account on the command line, such as:
heroku run rake db:setup --account a_specific_account