Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push rejected: error: failed to push some refs

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?

like image 498
Eric Avatar asked Mar 23 '12 00:03

Eric


People also ask

How do I fix error failed to push some refs to git?

We can fix the error: failed to push some refs to [remote repo] error in Git using the git pull origin [branch] or git pull --rebase origin [branch] commands. In most cases, the latter fixes the error.

What does failed to push some refs mean?

This means that someone else pushed a commit to the same branch you're pushing to, but you don't have that commit on your laptop yet. This can happen if it has been awhile since you ran "git pull" on a branch that many people contribute to, such as staging. To fix this issue, run: git pull origin <your-branch>

Can not push to GitHub?

Under Account settings, click on the Developer settings tab. Select Personal access tokens from the left tab. Select the Scope of access you want the token to have to your GitHub account. REMEMBER to copy your personal access token someplace SAFE!


1 Answers

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 
like image 191
blueshift Avatar answered Sep 27 '22 20:09

blueshift