Reputation: 85
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?
Upvotes: 4
Views: 6821
Reputation: 10227
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 fetch
ed, 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
If that doesn't work, then you'll have to contact your server administrator and ask them to allow you to delete branches and/or to force-update them.
Upvotes: 4
Reputation: 15821
Yeap you give this error cause you don't have latest changes from repository, so you should pull them.
git reset --hard HEAD
git pull --rebase // fetch and pull together
and after resolving conflicts (if they will exist) you will can doing push
git push origin master
Upvotes: 4