Heroku CLI

Heroku CLI cheatsheet — deploy apps, manage config vars, view logs, run bash. heroku create, git push heroku, heroku logs --tail, heroku config:set. Full reference.

7 min read

What it is

The Heroku Command Line Interface (CLI) is your primary tool for interacting with the Heroku platform, managing applications, deploys, add-ons, and more.

Installation

Linux

curl https://cli-assets.heroku.com/install.sh | sh

macOS

brew install heroku/brew/heroku

If you don’t have Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install heroku/brew/heroku

Windows

Download the installer from https://devcenter.heroku.com/articles/heroku-cli and follow the instructions.

Login

After installation, log in to your Heroku account:

heroku login

This will open a browser window for authentication.

Core Concepts

  • App: A deployed instance of your application on Heroku.
  • Add-on: A service (like a database or cache) that can be attached to your Heroku app.
  • Dyno: A lightweight virtual machine that runs your code. Heroku apps run on dynos.
  • Release: A specific version of your application’s code and configuration deployed to Heroku.
  • Slug: The compiled, ready-to-run version of your application code.
  • Buildpack: A set of scripts and dependencies used to compile your application code.

Commands / Usage

Authentication

  • heroku login Authenticate with your Heroku account.
  • heroku login -i Authenticate non-interactively using email and password (useful for scripting, though API keys are preferred).
  • heroku logout Log out of your Heroku account.

App Management

  • heroku create Create a new Heroku app. heroku create my-awesome-app Create a new Heroku app with a specific name.
  • heroku apps List all your Heroku apps.
  • heroku apps --team my-team List all apps for a specific Heroku team.
  • heroku open Open the current app in your default browser. heroku open -a my-awesome-app Open a specific Heroku app in your default browser.
  • heroku destroy Delete the current Heroku app. You will be prompted for confirmation. heroku destroy -a my-awesome-app --confirm my-awesome-app Delete a specific Heroku app without confirmation.
  • heroku ps -a my-awesome-app List the dynos running for a specific app.
  • heroku logs -a my-awesome-app Stream the logs for a specific app.
  • heroku config -a my-awesome-app View environment variables for a specific app.
  • heroku domains -a my-awesome-app List custom domains for a specific app.
  • heroku collaborators -a my-awesome-app List collaborators for a specific app.
  • heroku members -a my-awesome-app List members of a team associated with an app.

Git Integration & Deploys

  • heroku git:remote -a my-awesome-app Add the Heroku Git remote to your local repository.
  • git push heroku main Deploy your code to Heroku from the main branch. git push heroku develop:main Deploy code from your local develop branch to Heroku’s main branch.
  • heroku releases -a my-awesome-app List all releases for a specific app.
  • heroku releases:info <release_id> -a my-awesome-app Show details about a specific release.
  • heroku rollback <release_number> -a my-awesome-app Roll back to a previous release number. heroku rollback v10 -a my-awesome-app Roll back to a release tagged v10.
  • heroku buildpacks -a my-awesome-app List buildpacks for a specific app.
  • heroku buildpacks:add heroku/nodejs -a my-awesome-app Add a buildpack to a specific app.
  • heroku buildpacks:remove heroku/ruby -a my-awesome-app Remove a buildpack from a specific app.
  • heroku buildpacks:clear -a my-awesome-app Clear all buildpacks from a specific app.

Add-ons

  • heroku addons -a my-awesome-app List all add-ons for a specific app.
  • heroku addons:create heroku-postgresql:hobby-dev -a my-awesome-app Create a new Heroku Postgres hobby-dev add-on for the app.
  • heroku addons:destroy heroku-postgresql:hobby-dev -a my-awesome-app Destroy a specific add-on. You will be prompted for confirmation. heroku addons:destroy postgresql-rugged-31765 -a my-awesome-app --confirm my-awesome-app Destroy a specific add-on by its name, without confirmation.
  • heroku addons:upgrade heroku-postgresql:standard-0 -a my-awesome-app Upgrade an existing add-on to a new plan.
  • heroku pg:info -a my-awesome-app Show information about the PostgreSQL database attached to the app.
  • heroku pg:credentials:url -a my-awesome-app Display the DATABASE_URL for the attached PostgreSQL database.

Dynos & Processes

  • heroku ps:scale web=2 -a my-awesome-app Scale the web process type to run on 2 dynos.
  • heroku ps:scale worker=0 -a my-awesome-app Scale the worker process type to run on 0 dynos.
  • heroku ps:exec -a my-awesome-app Execute a command on a running dyno. heroku ps:exec bash -a my-awesome-app Open an interactive bash shell on a running dyno.
  • heroku dyno:restart -a my-awesome-app Restart all dynos for the app. heroku dyno:restart web.1 -a my-awesome-app Restart a specific dyno (e.g., the first web dyno).

Config Vars (Environment Variables)

  • heroku config -a my-awesome-app Show all config vars for the app.
  • heroku config:get DATABASE_URL -a my-awesome-app Get the value of a specific config var.
  • heroku config:set API_KEY=abcdef123 -a my-awesome-app Set a new config var or update an existing one.
  • heroku config:unset API_KEY -a my-awesome-app Unset (delete) a config var.
  • heroku config:push -a my-awesome-app Push local config vars to Heroku (requires local heroku config:set first).
  • heroku config:pull -a my-awesome-app Pull Heroku config vars to your local .env file.

Drains (Log Forwarding)

  • heroku drains -a my-awesome-app List log drains for the app.
  • heroku drains:add https://my-log-service.com/logs -a my-awesome-app Add a new log drain.
  • heroku drains:remove https://my-log-service.com/logs -a my-awesome-app Remove a specific log drain.

SSH

  • heroku ssh -a my-awesome-app Connect to a running dyno via SSH. heroku ssh web.1 -a my-awesome-app Connect to a specific dyno instance via SSH.

Plugins

  • heroku plugins List installed plugins.
  • heroku plugins:install heroku-ci Install a plugin.
  • heroku plugins:uninstall heroku-ci Uninstall a plugin.

Common Patterns

Deploying a specific branch and viewing logs

git push heroku main
heroku logs --tail -a my-awesome-app

Deploy your main branch and then continuously stream logs.

Setting multiple config vars at once

heroku config:set API_KEY=abcdef123 DATABASE_URL=postgres://user:pass@host:port/db -a my-awesome-app

Set several environment variables for your application.

Scaling dynos and checking status

heroku ps:scale web=5 -a my-awesome-app
heroku ps -a my-awesome-app

Increase the number of web dynos and then check the status of all dynos.

Rolling back a release and checking logs

heroku rollback v50 -a my-awesome-app
heroku logs --source app -a my-awesome-app

Revert to a previous release and then view logs specifically from your app’s dynos.

Adding a database and checking credentials

heroku addons:create heroku-postgresql:standard-0 -a my-awesome-app
heroku pg:credentials:url -a my-awesome-app

Provision a standard Heroku Postgres database and then get its connection URL.

Executing a command on a dyno

heroku ps:exec bash -a my-awesome-app

Open an interactive bash shell on one of your running dynos to debug.

Gotchas

  • heroku create names: If you don’t specify a name, Heroku generates a random, often amusing, name (e.g., ancient-forest-5376). Remember to use the generated name or specify your own.
  • heroku destroy confirmation: The --confirm flag is required to bypass the interactive prompt. Be very careful when using it, as it permanently deletes your app.
  • git push heroku: This command deploys your code. It triggers buildpacks to compile your app. Ensure your Procfile is correctly configured for your dyno types.
  • Config Vars are global: Config vars are set per app and are available to all dynos of that app. They are also sensitive, so avoid committing them directly into your code.
  • Dyno Types: Be mindful of the difference between process types (e.g., web, worker). You scale and manage them separately. web dynos typically handle incoming HTTP requests, while worker dynos handle background jobs.
  • Add-on Names: When destroying add-ons, you can use the generic type (e.g., heroku-postgresql) or the specific name assigned by Heroku (e.g., postgresql-rugged-31765). Using the specific name is safer if you have multiple instances of the same add-on type.
  • heroku ps:exec: This command connects to one dyno. If you have multiple dynos of the same type, it picks one. Use web.1, worker.2 etc. to target specific instances.
  • Log Streaming: heroku logs --tail will keep running until you press Ctrl+C.
  • Local vs. Remote: Commands like heroku config:pull and heroku config:push help synchronize environment variables between your local development setup (often a .env file) and the Heroku environment.