Skip to content

Instantly share code, notes, and snippets.

@1000miles
Last active July 20, 2023 03:45
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 1000miles/4547e07d7815b9701c145c3a3860ffb9 to your computer and use it in GitHub Desktop.
Save 1000miles/4547e07d7815b9701c145c3a3860ffb9 to your computer and use it in GitHub Desktop.
Most basic Heroku cli commands

Heroku CLI

Reference: https://devcenter.heroku.com/articles/heroku-cli-commands

1. Login/Logout

Login/Logout to/from Heroku from your Terminal shell

# Get your heroku username and password ready
$ heroku login 
$ heroku logout

2. Run commands

Run herokuapp locally

USAGE
  $ heroku local [PROCESSNAME]

OPTIONS
  -e, --env=env            location of env file (defaults to .env)
  -f, --procfile=procfile  use a different Procfile
  -p, --port=port          port to listen on

DESCRIPTION
  Start the application specified by a Procfile (defaults to ./Procfile)

ALIASES
  $ heroku local:start

EXAMPLE
  $ heroku local
  $ heroku local web
  $ heroku local web=2
  $ heroku local web=1,worker=2

Run a one-off command

$ heroku local:run bin/migrate

Navigate to the project folder, run Heroku command line tool (CLI) in the shell

$ heroku run bash

Run node in project folder

$ heroku run node path-to-file

# Example:
$ heroku run node bin/seed.js

3. Configuration

Get heroku configs of an app

$ heroku config

Create a new app on heroku

$ heroku apps:create

Show detailed app information

$ heroku apps:info

Rename an app

$ heroku apps:rename NEWNAME

Show list of available apps

$ heroku apps:stacks
   
 ▸    heroku-cli: update available from 6.13.19 to 6.99.0-ec9edad
=== ⬢ mind-the-board Available Stacks
* heroku-18
  heroku-16
  cedar-14
  container

Set node variables

heroku config:set NODE_ENV=production # set env to production
heroku config:set NODE_PATH=./src # Use ./src as node path

Adds a git remote to an app repo

$ heroku git:remote

4. Errors/Logs

View App Errors

$ heroku apps:errors

Display recent log output

$ heroku logs

$ heroku logs -t # Stream logs

5. Database

Show database info

  $ heroku pg [DATABASE]

Show current database settings

$ heroku pg:settings [DATABASE]

Delete all data in database

$ heroku pg:reset [DATABASE]

6. Pipeline

Setup pipeline

$ heroku pipelines:setup [NAME] [REPO]

# Example:
$ heroku pipelines:setup example githuborg/reponame -o example-org

List pipelines you have access to

$ heroku pipelines

Connect a github repo to an existing pipeline

$ heroku pipelines:connect [NAME]

# Example:
$ heroku pipelines:connect example -r githuborg/reponame

Create a new pipeline

$ heroku pipelines:create [NAME]

# Example:
$ heroku pipelines:create -a example-staging

Destroy pipeline

$ heroku pipelines:destroy PIPELINE

# Example:
$ heroku pipelines:destroy example

Compares the latest release of this app to its downstream app(s)

$ heroku pipelines:diff

OPTIONS
  -a, --app=app        (required) app to run command against
  -r, --remote=remote  git remote of app to use

EXAMPLES
  $ heroku pipelines:diff --app murmuring-headland-14719

Show list of apps in pipeline

$ heroku pipelines:info PIPELINE

# Example:
$ heroku pipelines:info example

7. Buildpacks

Show buildpacks

$ heroku buildpacks

 ▸    heroku-cli: update available from 6.13.19 to 6.99.0-ec9edad
=== mind-the-board Buildpack URL
heroku/nodejs

Add new app buildpack to project

$ heroku buildpacks:add BUILDPACK

Fetch info about a buildpack

$ heroku buildpacks:info BUILDPACK

Clear all buildpacks set on the app

$ heroku buildpacks:add BUILDPACK

Remove a buildpack set on the app

$ heroku buildpacks:remove [BUILDPACK]

Search for a buildpack

$ heroku buildpacks:search [TERM]

Set buildpacks

$ heroku buildpacks:set BUILDPACK

List versions of a buildpack

$ heroku buildpacks:versions BUILDPACK

8. Authentication

Output your current CLI authentication token

$ heroku auth:token

Display the current logged in user

$ heroku whoami

List oAuth authorizations

$ heroku authorizations

Create a new oAuth authorization

$ heroku authorizations:create

Show, revoke or update an existing oAuth authorization

$ heroku authorizations:info ID # show
$ heroku authorizations:revoke ID # revoke
$ heroku authorizations:update ID # update

$ heroku authorizations:rotate ID # update oAuth authorization token

9. Certifications

List certificates for an app

$ heroku certs

Add an SSL certificate to an app

$ heroku certs:add CRT KEY

EXAMPLES
  $ heroku certs:add example.com.crt example.com.key

Generate a key and a CSR or self-signed cert

$ heroku certs:generate example.com

Show cert information for an SSL cert

$ heroku certs:info

Print the correct key for the given certificate

$ heroku certs:key example.com.crt example.com.key

Remove an SSL cert from an app

$ heroku certs:remove

Generate 2fa recovery codes

$ heroku auth:2fa:generate-recovery-codes

Adds an SSH key for a user

$ heroku keys:add /my/key.pub

Remove an SSH key from the user

$ heroku keys:remove email@example.com

Remove all ssh keys for current user

$ heroku keys:clear

10. Git

Show all git remotes (on Github and Heroku)

$ git remote -v

Create a new heroku app

$ heroku create

Set git remote heroku to heroku app url

heroku git:remote -a thawing-inlet-61413

Rename heroku git remote

$ git remote rename heroku heroku-staging

Deploy to heroku master branch

$ git push heroku master

Deploy to another branch than heroku master

$ git push heroku testbranch:master

Deploy with -f force flag to avoid deployment conflicts

$ git add -A
$ git commit -m "heroku deployment message"
$ git push -f heroku

SSH Git

Configure to use ssh with Heroku globally

# Example
$ git config --global url.ssh://git@heroku.com # instead of https://git.heroku.com

Remove ssh with Heroku globally

$ git config --global --remove-section url.ssh://git@heroku.com/
@bsc-mat-01-19
Copy link

nice

@ph44cx
Copy link

ph44cx commented Apr 7, 2023

that was helpfull . thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment