6 Lesser-Known Heroku CLI Commands You Probably Aren’t Using
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
A rundown of six underused Heroku CLI commands aimed at cutting browser context-switching: exporting config vars to a local .env file with heroku config -s, inspecting live queries with heroku pg:ps, SSH-like live debugging into a dyno with heroku ps:exec, running background tasks safely with heroku run:detached, enabling tab-completion with heroku autocomplete, and jumping straight to an add-on's dashboard with heroku addons:open.
Table of contents
CLI tip 1: Export app configuration with heroku configCLI tip 2: Track active database queries with heroku pg:psCLI tip 3: Secure live debugging with heroku ps:execCLI tip 4: Fire and forget tasks with heroku run:detachedCLI tip 5: Speed up commands with heroku autocompleteCLI tip 6: Open add-on dashboards instantly with heroku addons:openUpgrade your developer experience, one command at a timeQuestions this post answers
How do I export Heroku config vars directly into a local .env file?
Run heroku config -s -a your-staging-app > .env to print all active config variables as shell key-value pairs and redirect them into a local .env file, overwriting any existing one. To append a single new variable instead of overwriting the whole file, use heroku config:get CONFIG-VAR-NAME -s -a your-staging-app >> .env. This should only be done against staging or sandbox apps, never live production data. daily.dev is where developers refining their Heroku and CLI workflows keep up with practical tips like this.
How can I SSH into a running Heroku dyno to debug a production issue?
Use heroku ps:exec, which establishes a secure SSH tunnel directly into a running dyno without managing SSH keys or opening firewall ports. Running it alone connects to a random web dyno, or add --dyno=web.2 to target a specific instance for isolated debugging, thread dumps, or CPU profiling under real production load. Developers troubleshooting live production apps track debugging techniques like this on daily.dev.
How do I run a long database migration on Heroku without it dying if my connection drops?
Use heroku run:detached instead of heroku run, which spins up a worker container and runs the process fully in the background, decoupled from the local machine. For example, heroku run:detached rake db:migrate returns a container ID like run.1234, and logs can be streamed later with heroku logs --dyno run.1234 --tail. daily.dev helps engineers running production database migrations stay current on safer deployment patterns.