Issue
I have updated my application code in GitHub, and I'd like to push those changes to my Heroku app.
Resolution
From the local repository's root directory, enter these commands:
$ git pull origin
- This pulls your repo from GitHub, assuming that
origin
is your GitHub remote repo. Change this depending on your local setup. This will make sure all changes committed to GitHub are in your local git repo.
$ git checkout branch-to-deploy
- This will checkout the branch you wish to deploy, for example
master
ormain
. You don't strictly need to do this if you are already working on this branch locally.
$ heroku git:remote -a app-name
- This will create the
heroku
remote in your local repo for the app you wish to deploy to.
$ git push heroku branch-to-deploy:main
- This pushes the local branch to the Heroku app's git repository. You can change
heroku
depending on what you do in step 3. You can also use a different branch here if you are not deploying frommain
locally. The last part always needs to bemain
ormaster
, as Heroku will only start builds for pushes to themain
ormaster
branch.
Additional Options
-
If you use the same repo for multiple apps, you can use the
-r
option on step 3 to have different remote names. For example,heroku git:remote -r heroku-dev -a heroku-dev-app
will make theheroku-dev
remote. You can then also add your production app to your local repo by doingheroku git:remote -r heroku-prod -a heroku-prod-app
. -
To push a specific commit, specify the commit SHA in step 4. For example,
git push heroku commit-ref-sha:main
wherecommit-ref-sha
is the specific commit SHA.