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
The remote doesn't allow non-fast-forwards.
Your best option is to git revert
all of the commits that shouldn't be there and be more careful in future.
git revert [commit]
will create a new commit that undoes whatever [commit]
did.
Steps to permanently enable force push in the following style
git push -f myrepo my-branch
Edit the file named "config" in the folder ending in ".git" on your remote repository
In git's command-line output from the failed push, look for the line that says something like:
error: failed to push some refs to 'ssh://user@some-remote-server.mycompany.com/srv/git/myrepo.git
then
ssh user@some-remote-server.mycompany.com
cd /srv/git/myrepo.git
vi config
Set "denyNonFastforwards" to false
In "config", set
[receive]
denyNonFastforwards = false
Now you can push from your local machine with -f
git push -f myrepo my-branch
For me, @svick 's hint pointed in the right direction. Since the git server I wanted to modify is actually my box, I logged into it and did a git config --global receive.denynonfastforwards false
to change all repos to accept a forced non-ff push. Didn't work out of the box. What I found was that in the config there already was receive.denynonfastforwards=true
set, and it couldn't be erased with git config --global --unset receive.denynonfastforwards
.
Doing the edit in the repo manually (vi config
) worked, though.
I solved by removing the master branch from protected and also default which is just over proted branch rules in setting of a repository.
The best way around this is to delete the remote branch and re-send it:
git push origin master --delete
git push origin master
The problem occurs as the current branch isn't configured properly for the PULL.
First check whether the upstream branch is properly configured for the pull using - git remote show origin
. You can find it under the section - Local branches configured for 'git pull':. If not, configure it using:
git config branch.MYBRANCH.merge refs/heads/MYBRANCH
Give appropriate branch name for the place holder - MYBRANCH