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

Chaining Pipelines in Azure DevOps

Singleton Design Pattern

Figma to Flutter: Parabeac-Core v1.2

Manage macOS Cross-Site Tracking with MDM

Getting started with Apache Allura and Contribution Guide

Run a cross cloud Kubernetes cluster of clusters

Unity3D HTTP Tutorial Part 1: set up some tests

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

Object-Oriented Programming (OOP)


The Window Object and var

7 JavaScript Concepts You Should Be Familiar With As a Developer