As I understand your scenario:
- You have local changes on a branch that has a remote.
- You encountered a conflict in a file when attempting to pull remote's changes into your local branch.
- You wish to instead overwrite the changes on your local branch to match those from the remote branch.
Simply put, it's doable, but it'd be better for you to resolve your conflicts instead in case you lose work.
We can't use git pull
for this since that does a git fetch
and git merge
operation, but what we can do is move the reference of your local branch to match that of the remote branch.
To do that, we will use git fetch
and git reset
.
git fetch && git reset --hard origin/BRANCH
This will throw your local changes away and your branch will now match the remote. I cannot stress enough that, if you do this, your local changes will be a fair bit tricker to recover (there are ways to do it through the reflog), so before you try this, be sure that this is what you want to do.
It sounds like you want to keep your local changes, pull the latest changes, and have your changes on top of that instead. That can be accomplished with git rebase BRANCH
. You'll still have to resolve the conflict, but the conflict will come before your work in history, making it slightly easier to deal with.
The final alternative to keep your original work is to stash it. Move your existing, non-pushed commit back into staging with git reset --soft HEAD~1
, and follow that up with git add . && git stash
so that your changes are kept in the stash. Should you want to apply/pop the stash to the branch, you'll still have to resolve the conflict, but it'll be more straightforward to do.