Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 313
Leahcim Avatar asked Sep 13 '12 22:09

Leahcim


2 Answers

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.

like image 82
Simone Carletti Avatar answered Oct 11 '22 16:10

Simone Carletti


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

like image 30
Joey Hoang Avatar answered Oct 11 '22 14:10

Joey Hoang