12

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?

sir-haver
  • 3,096
  • 7
  • 41
  • 85

1 Answers1

17

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360