Git push current branch to a remote with Heroku

cmaughan picture cmaughan · Mar 8, 2010 · Viewed 12.9k times · Source

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...

Answer

thekingoftruth picture thekingoftruth · Oct 2, 2010

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.

@nickgrim put it in the general form like so:

git config remote.[remoteRepositoryName].push [localBranchName]:[remoteBranchName]

Update:

Furthermore, modern git will conveniently run the above configuration command for you when you git push with the -u option:

git push -u staging staging:master