Git Errors when Pushing on Heroku

10,791

Solution 1

Heroku apps only run off of the master branch of the app repository (local to Heroku). If you want to deploy a branch to Heroku which isn't the master branch of your local repo, then you need to specify it. In your case it would be something like git push qa-remote dev:master (replace qa-remote with the actual name of the remote to your QA app), which says push my local dev branch to the master branch on qa-remote.

When you push like that for the first time, you'll likely need to add the -f flag to force push (non-fast-forward). Subsequently you should be able to push without the -f flag, as long as your local branch is up-to-date.

Solution 2

Try pushing with the -ff (fast-forward) option: git push heroku master -ff (replace heroku with the actual name of heroku remote).

Solution 3

Use the following command to push the update forcefully git push -f heroku master

Share:
10,791

Related videos on Youtube

yellowreign
Author by

yellowreign

Updated on June 25, 2022

Comments

  • yellowreign
    yellowreign almost 2 years

    I'm using Heroku and have a Rails app that is stable (production env), so I wanted to create something new where I can have quality assurance env where I can see how the changes will work on Heroku (as well as aggregating enhancements for releases) without always pushing to my production app.

    So what I did was create a new Heroku app, and also create a new branch locally (dev). My intention was to merge dev into master locally after I tested the change on my new Heroku QA app, and then push to Heroku production from my master branch.

    My approach might be a bad one with my landscape, I'm a newbie, so this was just my best guess at how to do this.

    But when I pushed my dev branch to my new QA app, it worked for pushing to a dev branch of the QA app, but not the master. So I couldn't see (and test) my changes on the new QA app. It seems to be telling me that I can only push the master branch to the master of my QA app, since I pulled already and everything was already up-to-date, but I receive this error:

    Pushing to [email protected]:foobar/QA.git
    To [email protected]:foobar/QA.git
    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]:foobar/QA.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
    hint: before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    Can someone please help me figure out what I'm doing wrong - either with my environments or with Git? Thank you.

    • matt
      matt about 12 years
      You're asking about Heroku, but your error message says Github. Make sure you’re pushing to the right place.
  • yellowreign
    yellowreign about 12 years
    Seems like there has to be a better way. Since multiple developers are working on the app, if there's a better set-up or another way to do it than fast-forwards, I think that would be better.
  • stevec
    stevec over 2 years
    This worked for me. I'm a little confused as to why it happened, as I simply merged a branch locally and pushed to GitHub, then to Heroku like normal. Seems odd.
  • stevec
    stevec over 2 years
    I worked out why it happened. I had run git commit --amend after pushing to heroku, which actually changes the commit SHA (didn't know it did that), so git figured heroku was ahead. In my case a straight git push --force heroku master was okay (since I was confident what was on heroku only differed by a commit message and nothing more)