Domanda

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 and git 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:

  1. In branch master: (a) git push pushes code to GitHub, and (b) git push heroku pushes code to my-app-staging on Heroku
  2. In branch production: (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)?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top