202

I have a project hosted on Heroku and it's gotten to the point where I want to make an alternate test server (so I can test Heroku workers without messing up production).

I have already set up my main Heroku remote running my trunk and a Heroku-dev remote on which I wish to run an alternate branch.

My problem is that since my alternate branch isn't master, Heroku won't build it.

$ git push heroku-dev test
counting objects ...
...
Pushed to non-master branch, skipping build.
To git@heroku.com:example-dev.git
* [new branch]      test -> test

Switching this build to master is not an option at the moment. Obviously one option is to create a whole new git repo that's a clone of my test branch, but that doesn't sound very ideal.

AlexQueue
  • 6,353
  • 5
  • 35
  • 44

4 Answers4

407

You can push an alternative branch to Heroku using Git.

git push heroku-dev test:master

This pushes your local test branch to the remote's master branch (on Heroku).


Comment from @Brian Armstrong:

Worth noting also, when you're ready to go back to master you need to do

git push -f heroku master:master 
rmcsharry
  • 5,363
  • 6
  • 65
  • 108
jordelver
  • 8,292
  • 2
  • 32
  • 40
  • 12
    Indeed - it's documented too: https://devcenter.heroku.com/articles/multiple-environments#advanced-linking-local-branches-to-remote-apps – Jon Mountjoy Jan 30 '13 at 10:52
  • 57
    Worth noting also, when you're ready to go back to master you need to do `git push -f heroku master:master` – Brian Armstrong Oct 31 '13 at 05:32
  • 5
    Is there a way to deploy using a non-master branch on Heroku, so as to keep Heroku `master` pristine for later promotion? – Eric Walker Sep 25 '14 at 23:38
  • 4
    No, Heroku always uses `master`. What is your use case? – jordelver Sep 26 '14 at 08:42
  • 1
    The obvious use case for what @EricWalker is requesting would be any situation when you want to test something on the live server that isn't ready to be committed. I could REALLY use this feature for debugging server-side Heroku quirks, given that Heroku's documentation is terrible – emersonthis Oct 21 '14 at 15:47
  • 1
    Not that obvious. You want to pushed uncommitted code to the *live* server? How are you going to do that? I don't see why you wouldn't just create a feature branch to debug Heroku's "quirks". – jordelver Oct 22 '14 at 08:13
  • 5
    @SDP Something I've done in the past for Heroku debugging is commit something, push it to Heroku, then (if that didn't work) try something else, commit it (with `git commit --amend`), push that to Heroku (using the `-f` flag) and repeat until fixed. Once it's fixed, make sure the final `--amend` is a nice clean commit with a sensible message and then move on to the next thing. That way you can test things all day long without multiple commits. It's not pretty but it gets the job done :) – Simon Nov 18 '14 at 15:50
  • 2
    I have a similar use case: I am exploring a new feature on a git branch that I'd prefer not to merge into master in case the idea fizzles. Ideally I'd be able to push this explore branch to my heroku staging app, debug it and either scrap the branch or merge it back into master when done exploring. This can't be that uncommon a need, I would think. – Matthew Cornell Feb 07 '15 at 23:40
  • 1
    @MatthewCornell I often create a separate throwaway Heroku app for that use case, then delete it when done. (It can be on the free service tier.) Just add it as another Git remote to your repository. – Marnen Laibow-Koser Feb 19 '15 at 20:08
  • @MarnenLaibow-Koser I did just that, but the issue is I still apparently need to merge into master (!) before doing so. I think I'd have to make a duplicate repository... – Matthew Cornell Feb 23 '15 at 16:23
  • 1
    @MatthewCornell `branch-remote/master` doesn't have to be the same branch as `origin/master`, so the suggestion in this answer works well (that is, `git push branch-remote branch:master`) and you don't have to merge into `origin/master`. I do wish Heroku would let you specify deploy branch as a config setting, but this isn't a bad alternative. – Marnen Laibow-Koser Mar 02 '15 at 02:10
  • @simon How do we REMOVE bad commits from the heroku app. `-f`` will force the merge, but it won't remove stuff from other pushes. Consider a situation where someone has pushed a test branch with a lot of wacky code. Then later I want to test a release branch. Pushing it with -f won't remove the preexisting wacky code right? It will just merge the release branch into it. So how to do we handle that situation? – emersonthis Mar 18 '15 at 21:08
  • 1
    "Pushing it with -f won't remove the preexisting wacky code right? It will just merge the release branch into it." This isn't correct @SDP. `--force` will overwrite commits, not merge them. A `git push --force` will make the Heroku app have the same commits that you push. – jordelver Mar 19 '15 at 08:50
  • @EricWalker yes, you can use the heroku web console to deploy non-master branch using the Deploy tab. Just connect your github repo and choose Manual deploy, then deploy a branch of your choice. Note that any new/updated submodules won't be fetched. This will leave the master in pristine state and a later force push is not needed. – hammady Feb 15 '17 at 07:32
  • 1
    Should the comment of @BrianArmstrong be part of answers? – Simon Puente Feb 29 '20 at 23:17
11

In my case, the default or base branch was develop, so i used:

          git push heroku develop:master 
Okpo
  • 375
  • 4
  • 9
2

In case git push heroku-dev test:master doesn't work for you, try git push heroku test:master. Remember the "test" in "test:master" is the name of the new branch you are on.

John
  • 313
  • 3
  • 8
-3

You will need to pull the remote branch first before you can push the non master branch.

Run following command in you local repository

git pull https://heroku:YOUR_HEROKU_API_KEY@git.heroku.com/YOUR_APP_NAME.git
kingkeamo
  • 274
  • 2
  • 6