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.
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With