Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: How to push different local Git branches to Heroku/master

Heroku has a policy of ignoring all branches but 'master'.

While I'm sure Heroku's designers have excellent reasons for this policy (I'm guessing for storage and performance optimization), the consequence to me as a developer is that whatever local topic branch I may be working on, I would like an easy way to switch Heroku's master to that local topic branch and do a "git push heroku -f" to over-write master on Heroku.

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

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

What I'd really like is a way to set this up in the configuration 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. If anyone knows how to accomplish that, please let me know!

The caveat for this, of course, is that this is only sensible if I am the only one who can push to that Heroku app/repository. A test or QA team might manage such a repository to try out different candidate branches, but they would have to coordinate so that they all agree on what branch they are pushing to it on any given day.

Needless to say, it would also be a very good idea to have a separate remote repository (like GitHub) without this restriction for backing everything up to. I'd call that one "origin" and use "heroku" for Heroku so that "git push" always backs up everything to origin, and "git push heroku" pushes whatever branch I'm currently on to Heroku's master branch, overwriting it if necessary.

Would this work?

 [remote "heroku"]     url = [email protected]:my-app.git     push = +refs/heads/*:refs/heads/master 

I'd like to hear from someone more experienced before I begin to experiment, although I suppose I could create a dummy app on Heroku and experiment with that.

As for fetching, I don't really care if the Heroku repository is write-only. I still have a separate repository, like GitHub, for backup and cloning of all my work.

Footnote: This question is similar to, but not quite the same as Good Git deployment using branches strategy with Heroku?

like image 221
Lawrence I. Siden Avatar asked Jun 04 '10 04:06

Lawrence I. Siden


People also ask

Can I push a different branch to Heroku?

Heroku only deploys code that you push to the master or main branches of the remote. Pushing code to another branch of the heroku remote has no effect.

How do I push to a different branch than a master?

In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.

How do I push the master branch of local repository to remote repository?

Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.


1 Answers

See https://devcenter.heroku.com/articles/git#deploying-code

$ git push heroku yourbranch:master 
like image 67
jassa Avatar answered Oct 11 '22 00:10

jassa