How to deploy a Git branch to Heroku

2 min readApr 21, 2022


Heroku logo
Heroku logo

This article goes over how to create and deploy a Git branch to Heroku via the CLI.



Let’s say you want to create a Heroku app named my-app.

Create it in Heroku dashboard or via the CLI:

heroku apps:create my-app # --team my-team

Optionally, you can add it to an existing pipeline:

heroku pipelines:add my-pipeline --app my-app # --stage development


Set the Git remote for your app:

heroku git:remote --app my-app

By default, the Heroku remote is named heroku:

$ git remote -vheroku (fetch)
heroku (push)

If you’re adding multiple remotes, it’s good practice to rename the remote:

git remote rename heroku heroku-my-app

Config Vars

Save the config vars or environment variables from another Heroku app other-app:

heroku config --shell --app other-app > .env.heroku

Set the config vars to my-app:

cat .env.heroku | tr '\n' ' ' | xargs heroku config:set --app my-app


Deploy by pushing your branch to the Heroku remote:

git push <remote> <branch>:master

For example:

git push heroku-my-app my-branch:master

Alternatively, you can replace master with main:

git push heroku-my-app my-branch:main


After you’re done, delete the app from the dashboard or via the CLI:

heroku apps:destroy my-app --confirm my-app

Then remove the remote:

git remote rm heroku-my-app