How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?

How do I ignore the following error message on Git pull?

Your local changes to the following files would be overwritten by merge

What if I want to overwrite them?

I've tried things like git pull -f, but nothing works.

To be clear, I only want to overwrite specific changes, not everything.


If you want remove all local changes - including files that are untracked by git - from your working copy, simply stash them:

git stash push --include-untracked

If you don't need them anymore, you now can drop that stash:

git stash drop

If you don't want to stash changes that you already staged - e.g. with git add - then add the option --keep-index. Note however, that this will still prevent merging if those staged changes collide with the ones from upstream.


If you want to overwrite only specific parts of your local changes, there are two possibilities:

  1. Commit everything you don't want to overwrite and use the method above for the rest.

  2. Use git checkout path/to/file/to/revert for the changes you wish to overwrite. Make sure that file is not staged via git reset HEAD path/to/file/to/revert.


Alright with the help of the other two answers I've come up with a direct solution:

git checkout HEAD^ file/to/overwrite
git pull

This works for me to override all local changes and does not require an identity:

git reset --hard
git pull

So many answers here that I hate to add yet another, but all of the above are clunkier than they need to be. I have to do this all the time as Git seems to become confused and says I have modified files that have not changed (can't revert because they didn't change, but I can't pull because they supposedly have changed) Simplest and fastest I've found so far is:

git stash
git stash drop
git pull

NOTICE: local changes will be lost


Here is a solution that throws away staged changes:

git reset file/to/overwrite
git checkout file/to/overwrite