Skip to content

Heroku CLI

Comprehensive Heroku CLI commands and workflows for deploying and managing applications on the Heroku platform.

Installation & Authentication

CommandDescription
heroku loginLogin to Heroku
heroku login -iLogin interactively
heroku logoutLogout from Heroku
heroku auth:whoamiShow current user
heroku auth:tokenDisplay auth token

App Management

Basic App Operations

CommandDescription
heroku appsList all apps
heroku apps:create myappCreate new app
heroku apps:destroy myappDelete app
heroku apps:infoShow app info
heroku apps:rename newnameRename app
heroku apps:openOpen app in browser

App Configuration

CommandDescription
heroku configShow config vars
heroku config:set KEY=valueSet config var
heroku config:unset KEYRemove config var
heroku config:get KEYGet specific config var
heroku buildpacksList buildpacks
heroku buildpacks:set heroku/nodejsSet buildpack

Deployment

Git Deployment

CommandDescription
git push heroku mainDeploy from main branch
git push heroku develop:mainDeploy from develop branch
heroku git:remote -a myappAdd Heroku remote
heroku releasesList releases
heroku releases:rollback v123Rollback to specific release

Container Deployment

CommandDescription
heroku container:loginLogin to container registry
heroku container:push webBuild and push container
heroku container:release webRelease container
heroku container:rm webRemove container

Dynos and Scaling

Dyno Management

CommandDescription
heroku psList dynos
heroku ps:scale web=2Scale web dynos
heroku ps:scale worker=1Scale worker dynos
heroku ps:restartRestart all dynos
heroku ps:restart web.1Restart specific dyno
heroku ps:stop web.1Stop specific dyno

Dyno Types

CommandDescription
heroku ps:typeShow dyno types
heroku ps:resize web=standard-1xResize dyno type
heroku ps:execSSH into dyno

Add-ons

Add-on Management

CommandDescription
heroku addonsList app add-ons
heroku addons:create heroku-postgresqlAdd PostgreSQL
heroku addons:create heroku-redisAdd Redis
heroku addons:destroy ADDON_NAMERemove add-on
heroku addons:upgrade ADDON_NAME:PLANUpgrade add-on plan
heroku addons:downgrade ADDON_NAME:PLANDowngrade add-on plan
CommandDescription
heroku addons:create sendgridAdd SendGrid email
heroku addons:create papertrailAdd Papertrail logging
heroku addons:create newrelicAdd New Relic monitoring
heroku addons:create schedulerAdd Heroku Scheduler

Database Operations

PostgreSQL

CommandDescription
heroku pgList PostgreSQL databases
heroku pg:infoShow database info
heroku pg:psqlConnect to database
heroku pg:reset DATABASE_URLReset database
heroku pg:backupsList backups
heroku pg:backups:captureCreate backup
heroku pg:backups:restore BACKUP_URL DATABASE_URLRestore backup

Database Maintenance

CommandDescription
heroku pg:maintenanceShow maintenance info
heroku pg:maintenance:runRun maintenance
heroku pg:statsShow database stats
heroku pg:diagnoseDiagnose database issues

Logging and Monitoring

Logs

CommandDescription
heroku logsShow recent logs
heroku logs --tailStream logs
heroku logs --source appShow app logs only
heroku logs --dyno web.1Show specific dyno logs
heroku logs --num 1000Show more log lines

Monitoring

CommandDescription
heroku ps:autoscale:enableEnable autoscaling
heroku ps:autoscale:disableDisable autoscaling
heroku metricsShow app metrics

Domains and SSL

Domain Management

CommandDescription
heroku domainsList domains
heroku domains:add example.comAdd custom domain
heroku domains:remove example.comRemove domain
heroku domains:info example.comShow domain info

SSL Certificates

CommandDescription
heroku certsList SSL certificates
heroku certs:add cert.pem key.pemAdd SSL certificate
heroku certs:removeRemove SSL certificate
heroku certs:auto:enableEnable automatic SSL
heroku certs:auto:disableDisable automatic SSL

Pipelines and Review Apps

Pipeline Management

CommandDescription
heroku pipelinesList pipelines
heroku pipelines:create mypipelineCreate pipeline
heroku pipelines:destroy mypipelineDelete pipeline
heroku pipelines:add mypipeline --stage stagingAdd app to pipeline
heroku pipelines:removeRemove app from pipeline

Promotions

CommandDescription
heroku pipelines:promote --remote stagingPromote to production
heroku releases:rollback --remote productionRollback production

Review Apps

CommandDescription
heroku reviewapps:enableEnable review apps
heroku reviewapps:disableDisable review apps

Teams and Collaboration

Team Management

CommandDescription
heroku teamsList teams
heroku membersList team members
heroku members:add user@example.comAdd team member
heroku members:remove user@example.comRemove team member

Access Control

CommandDescription
heroku accessList app collaborators
heroku access:add user@example.comAdd collaborator
heroku access:remove user@example.comRemove collaborator

CLI Plugins

Plugin Management

CommandDescription
heroku pluginsList installed plugins
heroku plugins:install PLUGIN_NAMEInstall plugin
heroku plugins:uninstall PLUGIN_NAMEUninstall plugin
heroku plugins:updateUpdate all plugins
CommandDescription
heroku plugins:install heroku-repoInstall repo plugin
heroku repo:resetReset git repository
heroku repo:purge_cachePurge build cache

Environment Management

Multiple Environments

CommandDescription
heroku git:remote -a myapp-staging -r stagingAdd staging remote
heroku git:remote -a myapp-production -r productionAdd production remote
git push staging mainDeploy to staging
git push production mainDeploy to production

Environment Variables

CommandDescription
heroku config --remote stagingShow staging config
heroku config:set NODE_ENV=production --remote productionSet production config

Maintenance and Troubleshooting

Maintenance Mode

CommandDescription
heroku maintenance:onEnable maintenance mode
heroku maintenance:offDisable maintenance mode
heroku maintenanceCheck maintenance status

Troubleshooting

CommandDescription
heroku run bashRun bash shell
heroku run rails consoleRun Rails console
heroku run python manage.py shellRun Django shell
heroku run nodeRun Node.js REPL

Performance

CommandDescription
heroku labs:enable prebootEnable preboot
heroku labs:disable prebootDisable preboot
heroku ps:waitWait for dyno to be ready

Best Practices

Deployment

  1. Use Pipelines: Set up staging and production environments
  2. Environment Variables: Store configuration in config vars
  3. Database Migrations: Run migrations during deployment
  4. Health Checks: Implement health check endpoints

Security

  1. SSL: Always use SSL for production apps
  2. Environment Separation: Keep staging and production separate
  3. Access Control: Limit collaborator access
  4. Secrets Management: Use config vars for sensitive data

Performance

  1. Dyno Sizing: Choose appropriate dyno types
  2. Caching: Implement caching strategies
  3. Database Optimization: Monitor and optimize database queries
  4. CDN: Use CDN for static assets

Monitoring

  1. Logging: Implement comprehensive logging
  2. Metrics: Monitor application metrics
  3. Alerts: Set up alerts for critical issues
  4. Error Tracking: Use error tracking services