How to deploy a Git branch to Heroku

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




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Develop a Mobile App for Your Restaurant Business

Masternode Hosting at Social Send Platform

A Gentle Introduction to TypeScript Decorators

10 Best Software Development Project Management Tools for External Teams

Inter-Integrated Circuits — I2C Basics (Part 2)

Face Library v1.1.0 release makes face detection more real-time on CPU

4 Python Pandas Functions That Serve Better With Dictionaries

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Some Basic Web Database Concepts And Terms

Do you really know Mongodb??

An Intro to APIs

RESTful API — What You Need To Know