I've been working on a web-app that gets pushed to heroku. The source is hosted on GitHub.
So git push
pushes the master branch to GutHub.
My git branch 'master' is connected to Heroku app 'my-app-staging
'
So git push heroku
pushes the app to my-app-staging.herokuapp.com
I've created a new Heroku app which will be the 'production' app, let's call it 'my-app-prod
'.
I have created a branch now called 'production
' (ie git checkout -b production
) and I've run git push -u origin production
to make it a managed branch at GitHub.
I now want to link the production
branch to my-app-prod.herokuapp.com
such that, when switched to the production
branch I can simply type git push heroku
(or perhaps git push prod-heroku production
or similar) and voila - the production branch is pushed to the production app.
What's the recommended way to link my production
branch to my-app-prod
on Heroku?
I've wallowed through Heroku's own docs on this but they all assume I've set up my apps using the heroku create
CLI, not set up my apps via Heroku's website, however the following paragraph just makes my head spin:
It’s simple to type
git push staging master
andgit push production master
when you’ve followed the steps above. Many developers like to take advantage of git’s branches to separate in-progress and production-ready code, however. In this sort of setup, you might deploy to production from your master branch, merging in changes from a development branch once they’ve been reviewed on the staging app. With this setup, pushing is a littler trickier:
Where I want to end up is as follows:
master
: (a) git push
pushes code to GitHub, and (b) git push heroku
pushes code to my-app-staging
on Herokuproduction
: (c) git push
pushes code to the production
branch on GitHub, and (d) git push heroku
pushes the production
code to my-app-prod
on Heroku.Given step 1 above is already in place and step 2 (c) is in place, how do I achieve step 2 (d)?
Heroku only deploys code that you push to the master or main branches of the remote. Pushing code to another branch of the heroku remote has no effect.
Head over to your heroku dashboard again, create a new app, go to it's settings tab and copy the heroku git url: https://git.heroku.com/sdk-heroku-staging.git , add it as aremote destination to your local repo: git remote add staging https://git.heroku.com/sdk-heroku-staging.git , here, “staging” is the name of our ...
If you want to set push. default for all git repositories (instead of just this one), add --global to the command. Now, you're in the staging branch and you're set up so that git pull and git push will work against your staging environment without any further arguments.
You should add another remote for my-app-prod named prod-heroku (replace GIT_URL with the Git URL that you can find in the settings page of my-app-prod in heroku):
git remote add prod-heroku GIT_URL git push prod-heroku production:master
This will push your local branch production to the remote branch master in prod-heroku so my-app-prod will get deployed with the code in production branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With