Search code examples
herokupushstaging

Pushing master branch to different instance of app


Let's say I have two versions of my app on heroku named 'my_app' and 'my_app_staging'. How do I push just to the staging version of my app?

When I use:

git push heroku master

It pushes to just 'my_app' which is what I want.

But I tried to set up another remote named 'staging' to 'my_app_staging' and when I used:

git push staging master

It pushed the master branch to both instances of the app instead of just the staging instance.


Solution

  • I came up with a solution that seems to work well. Instead of trying to push the master to the staging instance on heroku, I am now working on a branch and pushing the branch.

    Here is what I did to an existing production app, to add a staging app and push to it separately:

    Forking An Existing App

    First fork the app and duplicate the current database and environment variables:

    heroku fork -a app_production app_staging
    

    Add Remote

    Add new remote so you have something to push to from your local git:

    git remote add staging git@heroku.com:app_staging.git
    

    Update Staging

    Make new branch.

    git checkout -b new/branch
    

    After making the changes. Commit and push the new branch to the staging version of the app

    git add .
    git commit
    git push staging new/branch:master
    

    Update Master

    This only updates the staging app. Once you are satisfied that the staging instance is working. Merge the branch into the master and use this to push it to the production app:

    git push heroku master