DeveloperBreeze

Heroku CLI Cheat Sheet

Getting Started

Login

heroku login

Log in to your Heroku account from the command line.

Logout

heroku logout

Log out from your Heroku account.


App Management

Create an App

heroku create [app-name]

Create a new Heroku app. The app name is optional.

List Apps

heroku apps

List all Heroku apps you have access to.

Rename an App

heroku apps:rename new-name

Rename an existing app.

Delete an App

heroku apps:destroy --app app-name

Permanently delete an app.


Configuration

View Config Vars

heroku config

Display all configuration variables for an app.

Set a Config Var

heroku config:set KEY=value

Set a configuration variable.

Unset a Config Var

heroku config:unset KEY

Remove a configuration variable.


Deploying Code

Deploy with Git

git push heroku main

Push code from your local repository to Heroku (assuming main is your default branch).

Rollback

heroku rollback

Roll back to the previous release.

Releases

heroku releases

List recent releases.

View Logs

heroku logs --tail

Stream logs from your app in real-time.


Add-ons

List Add-ons

heroku addons

List all add-ons for an app.

Add an Add-on

heroku addons:create addon-name

Add an add-on to your app.

Remove an Add-on

heroku addons:destroy addon-name

Remove an add-on from your app.


Dyno Management

Scale Dynos

heroku ps:scale web=1

Scale the number of web dynos to 1.

View Dyno Status

heroku ps

List dynos for an app and their current status.

Restart Dynos

heroku ps:restart

Restart all dynos for an app.


Database Management

List Databases

heroku pg

List all Heroku Postgres databases for an app.

Open PostgreSQL Console

heroku pg:psql

Open an interactive console to the database.

Backup Database

heroku pg:backups:capture

Capture a backup of your database.

Restore Database

heroku pg:backups:restore BACKUP_URL DATABASE

Restore a database from a backup URL.


Collaborators

Add a Collaborator

heroku sharing:add email@example.com

Add a collaborator to your app.

Remove a Collaborator

heroku sharing:remove email@example.com

Remove a collaborator from your app.


Additional Commands

Open App in Browser

heroku open

Open the app in your default web browser.

Run a Command

heroku run command

Run a one-off command in your app environment.

Maintenance Mode

heroku maintenance:on

Enable maintenance mode.

heroku maintenance:off

Disable maintenance mode.


Help

Command Help

heroku help command

Display help for a specific command.


This cheat sheet provides a quick reference for the most essential Heroku CLI commands. You can always use heroku help for more detailed information about specific commands or visit the Heroku CLI documentation for more comprehensive details.

Continue Reading

Discover more amazing content handpicked just for you

Code
python

Configuring SQLAlchemy with PostgreSQL on Heroku: A Quick Guide

  • This code retrieves the DATABASE_URL from the environment.
  • If DATABASE_URL starts with postgres://, it replaces it with postgresql+psycopg2://.
  • The db instance is initialized with SQLAlchemy(app) for use with SQLAlchemy ORM.
  • The replacement of "postgres://" with "postgresql+psycopg2://" is necessary because of a compatibility issue between the URI format provided by Heroku and the URI format expected by SQLAlchemy.
  • When you provision a PostgreSQL database on Heroku, it sets an environment variable called DATABASE_URL with the connection string for your database.
  • This URI uses the format postgres://.

Nov 08, 2024
Read More
Tutorial

How to view tables on a PostgreSQL database hosted on Heroku

This will display a URL in the format: postgres://<user>:<password>@<host>:<port>/<database>

Open your database client, such as pgAdmin or DataGrip, and enter the details from the DATABASE_URL:

Nov 06, 2024
Read More
Tutorial

How to view your Heroku Apps

Once logged in, you’ll see a list of all your applications on the dashboard. You can click on each app to view details, manage settings, view metrics, and more.

Either method will allow you to easily access and manage your Heroku apps.

Nov 06, 2024
Read More
Article

Comparing AWS, DigitalOcean, Heroku, and Vercel: Understanding Cloud Service Providers and Their Offerings

Heroku is a platform-as-a-service (PaaS) provider that simplifies application deployment by abstracting away the complexity of managing servers. Its key strength is in enabling developers to focus on building applications without needing to handle infrastructure concerns such as server configuration or scaling. Heroku is especially useful for web applications that are written in languages like Ruby, Node.js, Python, and PHP.

Heroku is well-known for its ease of use, automatic scaling, and straightforward deployment process. However, this simplicity comes at a higher cost compared to IaaS services like DigitalOcean, making it best suited for developers who want to streamline application deployment rather than deal with detailed infrastructure management.

Oct 24, 2024
Read More
Cheatsheet

Docker Cheat Sheet

docker-compose logs
docker-compose scale service-name=num

Aug 01, 2024
Read More
Cheatsheet

Git Cheat Sheet

git tag -a tag-name -m "Message"

Create an annotated tag with a message.

Aug 01, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!