How do I force git pull to overwrite local files?
When working on a project with a team, you might stumble upon error messages like these when trying to pull from a remote repository:
error: Your local changes to the following files would be overwritten by merge: ...
-or-
error: Untracked working tree file 'images/icon.png' would be overwritten by merge
-or-
Please clean your repository working tree before checkout.
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. The last error often appears in VS Code or when switching branches with uncommitted changes.
No, git pull does not overwrite local changes. Git will abort the pull and show an error if your uncommitted changes conflict with incoming changes. This is a safety mechanism — your local work remains untouched until you explicitly decide what to do with it.
For this reason, there is no "force pull" feature in Git — but you can perform a couple of steps to achieve the same result: force pulling from the remote and overwriting your local files.
What about git pull --force?
You might expect that git pull --force would force Git to overwrite your local changes. It does not. The --force flag is passed down to git fetch, not git merge. It allows Git to update your local tracking references even when the remote history has been rewritten (e.g., after someone ran git push --force on the remote).
In other words, git pull --force:
- does NOT overwrite uncommitted changes
- does NOT overwrite local commits
- does NOT discard your working directory changes
It simply allows the fetch step to handle non-fast-forward ref updates. To actually overwrite local files, follow the steps below.
Step 1: Cleaning Up the Working Copy
First, you'll need to make sure your working copy doesn't contain these conflicting changes anymore. There are two ways to achieve this:
a) Saving Local Changes on a Stash
If you want to preserve your local changes, you can safely store them on a Stash. They will be available in case you want them back at a later point.
$ git stash --include-untracked
b) Discarding Local Changes
If you are sure that you don't need them anymore, you can discard your local changes completely:
$ git reset --hard
If you also have untracked / new files, you will have to use the "git clean" command to get rid of these, too:
$ git clean -fd
Please be careful with these commands: discarding local changes and untracked files cannot be undone!
Step 2: Pull Again
After you have cleaned up any local changes / untracked files that would have been overwritten, the pull will finally work:
$ git pull
Alternative: Using fetch + reset
Another common approach is to use git fetch combined with git reset --hard. This downloads the latest remote state and resets your local branch to match it exactly:
$ git fetch origin
$ git reset --hard origin/main
Unlike the stash + pull approach, this also discards any local commits that haven't been pushed yet. If you want to keep those commits around as a backup, create a branch first:
$ git branch backup-branch
$ git fetch origin
$ git reset --hard origin/main
You can also use the @{u} shorthand to refer to the upstream branch, regardless of its name:
$ git fetch origin
$ git reset --hard @{u}
If you also have untracked files that need to be removed:
$ git fetch origin
$ git reset --hard origin/main
$ git clean -fd
What About git checkout --force and Untracked Files?
If your error is related to switching branches rather than pulling, you might be using git checkout -f or git switch --force. Here's what you should know:
| Command | Tracked files (modified) | Untracked files |
|---|---|---|
git checkout -f |
Changes are discarded | NOT removed — switch is blocked if they conflict |
git switch --force |
Changes are discarded | NOT removed — switch is blocked if they conflict |
git clean -fd |
Not affected | Removed |
To force a branch switch when untracked files are in the way:
$ git clean -fd
$ git checkout -f main
Or with git switch:
$ git clean -fd
$ git switch --force main
Auto-Stashing in Tower
If you're using the Tower Git client, you’ll notice that it helps you avoid these situations: whenever you have uncommitted local changes present and want to perform an action like Pull, Checkout or Merge, Tower will automatically offer to store these changes safely on a Stash.
This way, you neither have to take any extra steps nor do you have to think about this anymore.
Learn More
- Check out the chapter Integrating Remote Changes in our free online book
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.