Search code examples
githerokustaging

Git - make development and master track different repos. Sensible?


I have a project which is in git and deploys to heroku. The remote url is git@heroku.com:myappname.git and the .git/config looks like this:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  url = git@heroku.com:myappname.git
[branch "master"]
  remote = origin
  merge = refs/heads/master

I just made a new heroku app called "myappname-staging" which i want to use as a staging site for this app. I was thinking that i would set it up so that the "master" branch pushes to the production remote and the "development" branch pushes to the staging remote. Is this the sensible/conventional way to handle this situation?

I can't quite figure out how to do this. When i made the staging app on heroku it gave me this back:

Creating myappname-staging.... done
http://myappname-staging.heroku.com/ | git@heroku.com:myappname-staging.git
Git remote heroku added

And my config now looks like this:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  url = git@heroku.com:myappnamestef.git
[branch "master"]
  remote = origin
  merge = refs/heads/master
[remote "heroku"]
  url = git@heroku.com:myappname-staging.git
  fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "staging"]
  url = git@heroku.com:myappname-staging.git
  fetch = +refs/heads/*:refs/remotes/staging/*

Can anyone set me straight?

thanks, max


Solution

  • Add this:

    [branch "development"]
      remote = staging
      merge = refs/heads/master
    

    You can do that from the command line via:

    $ git config branch.development.remote staging
    $ git config branch.development.merge refs/heads/master
    

    That will set up the development branch to tracking the master branch on staging.