I would like my local branch to be identical to the remote one. When I pull from the remote one, I'm getting conflicts, and in this case I would like not to resolve them and just get the latest version from the remote branch.
To hard pull I use in my local branch:
git reset -- hard
git pull
Nevertheless, when pulling I'm getting the error:
Automatic merge failed; fix conflicts and then commit the result.
Why? How can I pull the remote branch with overwriting? I thought of a workaround to just delete my local branch and create a new one and then pull, but is there a better way?
Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.
The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.
Checkout old commits Since this has the potential to overwrite local changes, Git forces you to commit or stash any changes in the working directory that will be lost during the checkout operation. Unlike git reset , git checkout doesn't move any branches around.
There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.
Try doing a git fetch
to bring the (local) remote tracking branch up to date with the remote version, then hard reset your local branch to that:
# from local
git fetch origin
git reset --hard origin/local
As to why you are still getting merge conflicts even after a hard reset, this could be explained by a few things. The general explanation would be that your local branch has commits which are not present in the remote version. In that case, Git cannot simply fast-forward your local branch, and must resort to doing a merge instead, which can lead to conflicts.
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