visit our site

How to set up the Heroku tools for deployment with multiple accounts

In Development, Random

by Leonid Shevtsov by February 5, 2013

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.

  1. Download the Heroku Toolbelt – this is the recommended way to install Heroku utilities.

  2. Install the heroku-accounts plugin – this will let you use multiple Heroku accounts in parallel.

  3. Now you can login to your account.

    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?

  4. Go to the project folder. Time to enable deployment.

    Here [app_name] is the public name of the Heroku app (its URL would be [app_name]

    These commands add a heroku git remote that will be used for deployment. The entire configuration is stored in .git/config.

  5. Deploy away!

If the app has not yet been deployed, instead of the step 4 you’d have to create the app:

The second heroku accounts:set is needed to point the git remote URL to the hostname configured in the step 3.

Random tips

  • 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:

  • If you’d like to deploy a different branch (which is risky, but useful for staging), do

    Remember, just pushing the branch to Heroku will do nothing, it has to be pointed at by master.

  • 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:

* Railsware is a premium software development consulting company, focused on delivering great web and mobile applications. Learn more about us.
  • Lokase

    Leonid, thank you for this write up. Was having issues with the first deploy. I was not using the correct sequence of command (specifically resetting the heroku accounts after I created the heroku app). You saved my sanity.

  • Dani Gellis

    This is a great write-up, thanks.

    I just also wanted to let folks know that in many cases there is an easier option: become a “collaborator” on the project on Heroku. When the project owner account is logged in to Heroku, all they have to do is go to the “access” tab and click the “edit” button to add a new collaborator. Have them enter the email address you use for your Heroku account, and you’ll get an email saying that you have access to the app and encouraging you to clone it. Super easy.

    A collaborator has access to everything the owner does except
    1) deleting or renaming the app
    2) adding or removing paid add-ons
    3) viewing invoices

  • Jesse Farmer

    3px of padding-top in a div that the tweet button is in, will vertically align those buttons properly.

  • Jesse Farmer

    Awesome article. Thanks. It helped.

    I did run into a problem that others might:

    I am pushing TO multiple Heroku accounts (I don’t want the bill, right?) FROM my single Git account, Heroku blocked me from pushing after I created the new app with the new account.

    There is probably a CLI command to do this, but I had to go into the NEW Heroku account to add myself as a collaborator on the Accounts tab of the newly-created app.

    Thanks again.

Signup for our weekly newsletter

Want to get more of Railsware blog?

RSS Feed

We're always ready to help!

Contact us