NOTICE: When I say "appname" it means enter your own! It's not a command or name native to git or Heroku.
By default, your one and only remote is called "heroku". This is why you do things like $ git push heroku master, you're pushing to the master branch of heroku
. What we want is two remotes: one staging, one production. You can view your remotes by typing...
$ heroku apps:create staging-appname
$ git remote -v
// this should return:
// heroku [email protected]:appname.git (fetch)
// heroku [email protected]:appname.git (push)
So, lets rename that default heroku
git remote to a staging, production one.
$ git remote rename heroku production
Now, create a new repo. This is essentially splitting your local git repo to be able to push to two different remotes. Also, from now on, when you run things like $ heroku run rake db:migrate, it's going to ask you to specify which app you want to do it to. Lets add our new remote to the local repo, that points to the 2nd app you made.
$ git remote add staging [email protected]:staging-appname.git
Now lets run that remote command again! $ git remote -v:
production [email protected]:appname.git (fetch)
production [email protected]:appname.git (push)
staging [email protected]:staging-appname.git (fetch)
staging [email protected]:staging-appname.git (push)
Awesome; it worked. Note: to push, you must now specify which remote instead of just saying $ git push heroku master
Example workflow:
// Add files you've been working on
$ git add .
// Commit to your local repo
$ git commit -m "Made some changes"
// Push to `staging`
git push staging master
// Everything look ok on your staging app? Cool.
git push production master