views:

772

answers:

6

I'm trying to create a staging branch on Heroku, but there's something I don't quite get.

Assuming I've already created a heroku app and setup the remote to point to staging-remote, If I do:

git checkout -b staging staging-remote/master

I get a local branch called 'staging' which tracks staging-remote/master - or that's what I thought....

But:

git remote show staging-remote

Gives me this:

remote staging
  Fetch URL: [email protected]:myappname.git
  Push  URL: [email protected]:myappname.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    staging-remote merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

As you can see, the pull looks reasonable, but the default push does not. It implies that if I do:

git push staging-remote

I'm going to push my local master branch up to the staging branch. But that's not what I want.... Basically, I want to merge updates into my staging branch, then easily push it to heroku without having to specify the branch like so:

git push staging-remote mybranch:master

The above isn't hard to do, but I want to avoid accidentally doing the previous push and pushing the wrong branch... This is doubly important for the production branch I'd like to create!

I've tried messing with git config, but haven't figured out how to get this right yet...

A: 

I couldn't figure out a way to do this, but in the end I found a handy rake task to make it easy: http://www.jbarnette.com/2009/11/10/deploying-to-heroku.html

cmaughan
+1  A: 

From the page Everiday Git with 20 commands or so :

http://www.kernel.org/pub/software/scm/git/docs/everyday.html

It seems that you can achieve what you want to do by adding a config directive to your local git repository, something like :

git config remote.staging-remote.push mybranch:refs/remotes/staging-remote/master

Then, if you do a git push from your mybranch local branch, it should be pushed to the master branch of your staging-remote remote.

Nevertheless, please verify with git remote show staging-remote and carefully test it before using it, as I'm far from a git expert...

juba
+1  A: 

I have a branch called heroku, and this worked for me:

git config remote.heroku.push heroku:master

the problem you're facing is heroku ignores all branches other than master.

MatthewFord
A: 

I'm having the same problem trying to figure out how to deal with Heroku's policy of ignoring all branches but 'master'. It kinda defeats the whole point of keeping separate branches if you can only ever test the master branch on Heroku.

The consequence of this restriction is that whatever local topic branch I may be working on, I'd like an easy way to switch Heroku's master to that local topic branch and do a "git push -f" to over-write master on Heroku. Needless to say, it would be a very good idea to have a separate remote repository (like Github), to back everything up without this restriction. I'd call that one "origin" and use "heroku" for Heroku so that "git push" always backs up everything.

What I got from reading the "Pushing Refspecs" section of http://progit.org/book/ch9-5.html is

git push heroku local-topic-branch:refs/heads/master

What I'd really like is a way to set this up in the config file so that "git push heroku" always does the above, replacing "local-topic-branch" with the name of whatever my current branch happens to be.

I may ask this as a new question, to see if anyone else has figured out how to do this.

lsiden
`git config remote.heroku.push HEAD:master`
Chris Johnsen
+1  A: 

From the book "O’Reilly - Version Control with Git" page 184 | Chapter 11: Remote Repositories

During a git push operation, you typically want to provide and publish the changes you made on your local topic branches. To allow others to find your changes in the remote repository after you upload them, your changes must appear in that repository as topic branches. Thus, during a typical git push command, the source branches from your repository are sent to the remote repository using a refspec such as:

+refs/heads/*:refs/heads/*

This refspec can be paraphrased as: From the local repository, take each branch name found under the source namespace refs/heads/ and place it in a similarly named, matching branch under the destination namespace refs/heads/ in the remote repository. The first refs/heads/ refers to your local repository (because you’re executing a push), and the second refers to the remote repository. The asterisks ensure that all branches are replicated. ...


That’s why the example from juba should fail. the corrected refspec should be:

git config remote.staging-remote.push +refs/heads/local_branch_name:refs/heads/master
mtin79
A: 

I have tested it and juba and MatthewFord's versions work perfectly!

git config remote.staging.push staging:master

This pushes my local topic branch named staging into remote branch master on the remote repository named staging

thekingoftruth