Heroku: how to "git pull" after 'git push -f'

25,729

Solution 1

Forcing your git push was not a good idea because you lost any commit that was done by you or other collaborators you were missing on your working copy.

Before pushing, you should have either merged or rebased the upstream changes into your local working copy.

To merge the changes locally

$ git pull heroku master
$ git push heroku master

To rebase the changes locally

$ git pull --rebase heroku master
$ git push heroku master

BTW, now that you have pushed your changes, you actually don't need to do anything else. The remote repository already contains all your changes.

If for whatever reason the $ git status command is returning outdated references, simply run

$ git pull heroku

to fetch all the remote changes. Please note that unless you specify a target branch (or you have the tracking branch enabled), git pull will simply download (and not merge) the upstream changes.

Also note that Heroku should not be considered a git hosting. It means that it's extremely uncommon to perform a git pull from Heroku. Instead, you should use a git hosting (such as GitHub or BitBucket) to store your repository and only perform push to Heroku to deploy the application.

Solution 2

That error basically means that there is code in the repo that is newer than the code you're trying to push to it.

you have to do a pull and update your own working repository then push again, or just force a push

git pull heroku master

As a side note, if you aren't familiar with all the git commands, I would recommend you use a GUI as it may make the whole process a lot less overwhelming.

There are plenty of great clients here: http://git-scm.com/downloads/guis

Share:
25,729
Leahcim
Author by

Leahcim

I'm pretty hopeless at programming but I'm enjoying trying to learn it (rails, php, javascript, jquery)... Backbone underscore twitterbootsrap http://jsfiddle.net/mjmitche/RRXnK/119/

Updated on July 09, 2022

Comments

  • Leahcim
    Leahcim almost 2 years

    I got this error message (copied below) after trying to push to Heroku. I initially set up a facebook canvas app and selected the hosting on heroku options. It gave me a heroku url, which I added as a remote on the app I was developing on my machine

    heroku git:remote -a desolate-springs-1684
    

    But when I pushed, I got this error

    error: failed to push some refs to '[email protected]:desolate-springs-1684.git'
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes (e.g. 'git pull') before pushing again.  See the
    'Note about fast-forwards' section of 'git push --help' for details.
    localhost:nhl michaelmitchell$ 
    

    So I did

    git push -f heroku master
    

    But now I apparently have to do a 'git pull'. However, what do i put after the 'git pull'? The name of the heroku url? or something else?