Short version

$ heroku fork --from stark-eyrie-15516 --to automated-tester-staging
$ heroku info -a automated-tester-staging
Git URL:       https://git.heroku.com/automated-tester-staging.git
$ git push staging

Long version

Sometimes it’s nice to have a staging environment for your heroku app (i.e. staging, prod etc).

To create a fresh staging environment for your app we first need to fork it, and then create a git remote name like ‘staging’ and point it to your newly forked app.

1. Fork app

> heroku fork -a appname myapp-staging
...
Fork complete, view it at http://myapp-staging.herokuapp.com (i.e. http://nutshell-staging.herokuapp.com)
  • appname is the name of the heroku app you want to fork. If your’ve already created a heroku app, it will have a name like ‘warm-wave-1832’.
  • to see a list of your heroku apps type:
> heroku apps
  • yourapp-staging is the name of the staging app you want to create (must be unique to heroku, so something like myapp-staging)

2. Create git repos name and point it to your newly created staging environment.

Before you can add a remote to your staging repos, you need the git url.
You can get that by going:

> heroku info -a myapp-staging
Git URL: git@heroku.com:myapp-staging.git

Now simple create a new git remote and point it to your newly created staging URL above:

> git remote add staging git@heroku.com:myapp-staging.git

3. Test.

> git remote -v

heroku git@heroku.com:myapp.git
origin https://github.com/xxx/pss.git
staging git@heroku.com:myapp-staging.git (fetch)

You should now see x3 git remotes.
One for your original ‘heroku’ app.
One for your github repos ‘origin’.
And your new one – ‘staging’

If you want to get rid of the ‘heroku’ git remote and replace it with ‘prod’ do this:

> git remote rm heroku
> git remote add prod git@heroku.com:myapp.git

Now the fun starts! You should now be able to do stuff like this:

> git push prod
> git push staging

And each will go to their own respective heroku instances.

Advertisement