Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Our remote master branch somehow got messed up. Current development code is on the master branch along with the latest commits. Obviously, the development code is not ready for the master branch.

So on my local repository, I did a reset to the latest tag, git reset --hard (Tag). The master branch is now correct on my local repository. Now when I try to push the changes on to the remote repository, git push origin master, I get an error:

To (REMOTE GIT REPOSITORY LOCATION)
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '(REMOTE GIT REPOSITORY LOCATION)'
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.

So after looking around I found out the --force option. So I did a force push on to the remote repository, git push --force origin master, and I still got an error:

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To (REMOTE GIT REPOSITORY LOCATION)
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to '(REMOTE GIT REPOSITORY LOCATION)'

I can't do a pull on master, because it contains development code which can't be on master.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
675 views
Welcome To Ask or Share your Answers For Others

1 Answer

The message means that you're not allowed to do non-fast-forward push.

Your remote repository has most likely denyNonFastforwards = true in its config. If you change that, git push --force should work.

To change the setting, you need access to the machine with the remote repository. From there, do git config receive.denynonfastforwards false.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...