git push rejected: error: failed to push some refs

Eric picture Eric · Mar 23, 2012 · Viewed 218.3k times · Source

I know people have asked similar questions, but I believe the causes of their problems to be different. I did a hard reset because I had messed up my code pretty bad

 git reset --hard 41651df8fc9

I've made quite some changes, I've made some commits and now that I'm trying to push all these commits into the server I get the following error:

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]'

Git suggests to do a git pull and that's what other people have suggested to other users. However, I believe that a git pull will merge my current code with the code that I don't want anymore (head revision). How can I do a push and forget about the version/revisions ahead of me?

Answer

blueshift picture blueshift · Mar 23, 2012

git push -f if you have permission, but that will screw up anyone else who pulls from that repo, so be careful.

If that is denied, and you have access to the server, as canzar says below, you can allow this on the server with

git config receive.denyNonFastForwards false