user2921643 user2921643 - 2 months ago 10
Git Question

Conflicts after git reset --hard

I've got a branch named

master
and I want to reset all changes made on this branch. Need to move all commits from branch named
origin/d
to
master
.
So this is what I did (on branch
master
):

git fetch -all
git reset --hard origin/d
git clean -f -d
git push origin master --force


I've got following message:

remote: error: denying non-fast-forward refs/heads/master (you should pull first)


But I don't want to pull, I just want move all commits from branch
d
to branch
master
(ignoring all local/non-local commits on branch
master
).

When I put
git pull
I've got many conflicts that I do not want to resolve. Could anyone help me and tell me what is the simplest way to do that?

Answer

The error message indicates that (1) your server is disallowing forced updates (the --force argument), and (2) for some reason Git wants to push m to master.

To temporarily work around the second issue, you can do:

git push origin m:refs/heads/m --force-with-lease

(It's better to use --force-with-lease rather than --force, because the former will only overwrite if your remote-tracking branch is up-to-date. If someone else happened to push commits since you last fetched, then --force will overwrite those, causing work to be lost.)

However, if your server is disallowing forced updates, then it will probably reject that command as well. If you have admin access to your server, then one option is to change that. Otherwise, to work around that, you should be able to delete the branch and then push:

git push origin --delete m
git push origin m:refs/heads/m