⚠ Warning:

Any uncommitted local change to tracked files will be lost, even if staged.

But any local file that's not tracked by Git will not be affected.


First, update all origin/<branch> refs to latest:

git fetch --all

Backup your current branch (e.g. main):

git branch backup-main

Jump to the latest commit on origin/main and checkout those files:

git reset --hard origin/main

Explanation:

git fetch downloads the latest from remote without trying to merge or rebase anything.

git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/main.


Maintain current local commits

[*]: It's worth noting that it is possible to maintain current local commits by creating a branch from main before resetting:

git checkout main
git branch new-branch-to-save-current-commits
git fetch --all
git reset --hard origin/main

After this, all of the old commits will be kept in new-branch-to-save-current-commits.

Uncommitted changes

Uncommitted changes, even if staged (with git add), will be lost. Make sure to stash or commit anything you need. For example, run the following:

git stash

And later (after git reset), reapply these uncommitted changes:

git stash pop

Which may create merge conflicts.

Answer from RNA on Stack Overflow
🌐
Codecademy
codecademy.com › article › force-git-pull
How to Force Git Pull to Overwrite Local Changes in Git | Codecademy
One of the most effective ways to force git pull and ensure our local branch is an exact match with the remote branch is by using the git reset --hard command. This approach is ideal when we want to completely discard the local changes, whether ...
Discussions

Does git pull not overwrite local code always?
What you're missing is that the files you edited did not have any changes, because the other devs didn't change those files. There cannot be a conflict on a file if only one person edited the file. Technically git tracks these changes No, it doesn't. When you do e.g. git diff, only then does Git calculate the diff. It doesn't "store" or "follow" the changes in any way; Git only actually records your changes when you add them. More on reddit.com
🌐 r/git
11
4
December 12, 2019
How can I use `git pull` while ignoring local changes? - Stack Overflow
@Cascabel It means to revert all the local changes, uncommit all the local commits, delete all the local new files and directories, undelete all the locally deleted files and directories, etc. In short, just run a command as if rm -rf local_repo && git clone remote_url. ... If you mean you want the pull to overwrite ... More on stackoverflow.com
🌐 stackoverflow.com
How to overwrite local changes from remote repository?
I don't believe there is a way to do this with 1 command, there is no option for clone that allows it to override existing files. You could have a script that force pulls if the local repo exists and clones if it doesn't. More on reddit.com
🌐 r/git
5
8
March 11, 2022
Git fetch overwrote my local changes, what happened exactly?

A fetch is quite safe. One of the problems with these GUIs that attempt to make git easier is that they tend to do a lot more in the background than you expect, like whatever happened here. I was once working on a project with someone who was using the official GitHub Desktop app, and every time they fetched, it would fetch, merge, and push the result, so I was getting all their half-baked changes even though they just thought they were pulling in mine.

You're really best off only using the commands directly, or using wrappers that you've read the source code for and understand.

More on reddit.com
🌐 r/git
17
3
July 9, 2017
🌐
Git Tower
git-tower.com › learn › git faq › how do i force git pull to overwrite local files?
How do I force git pull to overwrite local files? | Learn Version Control with Git
1 week ago - 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.
🌐
Graphite
graphite.com › guides › git-pull-overwrite-local-changes
How to overwrite local changes when executing a git pull command
The behavior of git pull regarding ... pulled. By default, git pull does not overwrite unstaged local changes unless there is a conflict between your local changes and the changes coming from the remote repository....
🌐
freeCodeCamp
freecodecamp.org › news › force-pull-in-github-how-to-overwrite-on-local-changes-with-git
Force Pull in GitHub – How to Overwrite on Local Changes with Git
February 16, 2023 - To do this, you need to run the git fetch command like so: ... The command above will download the latest updates from the remote and sync your local repository to the remote. Next, execute the git reset --hard command.
🌐
freeCodeCamp
freecodecamp.org › news › git-pull-force-how-to-overwrite-local-changes-with-git
Git Pull Force – How to Overwrite Local Changes With Git
July 20, 2020 - When your uncommitted changes are significant to you, there are two options. You can commit them and then perform git pull, or you can stash them.
Find elsewhere
🌐
Reddit
reddit.com › r/git › does git pull not overwrite local code always?
r/git on Reddit: Does git pull not overwrite local code always?
December 12, 2019 -

Our team has a project repo setup and all of us devs have forked that repo and cloned it to our local machines. So all of us have origin and root configured respectively where root is the actual repo and origin is our individual forks.

We always take a pull from root before pushing to origin and raising a merge request. The good practice.

Now I had some task on which I had to work on which will take me 2 days to complete. Before starting to work on it, I took a pull from root and started coding. After 2 days as I finished, before pushing to my origin, I took a pull from root because I saw other devs had some commits of their own and I will resolve the merge conflicts (if any) on my local before raising my own merge request. However , I did not commit my local changes, just saved them.

But git pull was successful and it did not prompt me to commit local changes else it'll be lost in the pull operation. So i checked those other commits and I saw none of them pertained to the files I changed, but were to different files. So i committed my changes, pushed to origin, the usual steps.

So will git pull not overwrite changes in my uncommitted local when the same file has not been modified in root? Technically git tracks these changes and must be unsure what to do as I haven't committed them. Either I should stash or commit? What am I missing or lacking the understanding of?

🌐
SourceBae
sourcebae.com › home › how to force git pull to overwrite local files [2026 guide]
How to Force Git Pull to Overwrite Local Files [2026 Guide] - SourceBae
February 11, 2026 - No. Regular git pull will never overwrite uncommitted changes – it will fail with an error instead. You must explicitly use git reset --hard or git pull --force to overwrite local changes.
🌐
Lineserve
lineserve.net › home › blog › how to force git pull to overwrite local files: complete step-by-step guide
How to Force Git Pull to Overwrite Local Files: Complete Step-by-Step Guide — Lineserve Blog
December 11, 2025 - Force a Git pull to overwrite local files using git fetch with git reset –hard, or preserve work with git stash, avoiding untracked-file merge errors. Git·Stephen Ndegwa·Published Dec 11, 2025·Last updated Jul 5, 2026·4 min read ... Ever run into that frustrating Git error where a git ...
🌐
DEV Community
dev.to › smpnjn › how-to-force-overwrite-local-changes-with-git-pull-p62
How to force overwrite local changes with 'git pull' - DEV Community
September 4, 2022 - You can see all other branches available to switch to by running git branch --list. Finally, we use git reset --hard origin/master to force git pull. This will force overwrite any local changes you made.
🌐
Fjolt
fjolt.com › article › git-force-overwrite-with-git-pull
How to force overwrite local changes with 'git pull'
You can see all other branches available to switch to by running git branch --list. Finally, we use git reset --hard origin/master to force git pull. This will force overwrite any local changes you made.
🌐
Daehnhardt
daehnhardt.com › home › git survival guide › preserve your local changes on git pull
Preserve your local changes on Git Pull - Daehnhardt
August 2, 2023 - We have solved the “Your local changes to the following files would be overwritten by merge” error with just one combined Git command, which keeps our local changes merged on top of pulled remote changes. git pull --rebase --autostash stashes ...
🌐
CodeLucky
codelucky.com › home › how do i force git pull to overwrite local files? – version control insights
How do I force git pull to overwrite local files? - Version Control Insights - CodeLucky
August 30, 2025 - To safely force a pull and overwrite local files, you need to reset your local changes first or fetch and reset to remote explicitly. This method involves discarding local changes by resetting the branch to match the remote, then pulling the ...
🌐
Expertbeacon
expertbeacon.com › home › git pull force – how to expertly overwrite local changes
Git Pull Force – How To Expertly Overwrite Local Changes - ExpertBeacon
August 21, 2024 - Let‘s start with the blunt force method: obliterating all uncommitted local work and resetting your state to match origin exactly. Take care, this is destructive and permanent! Before git pull --force, both remote and local repos have separate ...
🌐
Continuously Merging
articles.mergify.com › git-pull-overwrite-local-changes
Git Pull Overwrite Local Changes A Practical Guide
October 30, 2025 - Any uncommitted local changes will be gone for good. origin/main: This is the destination. You're telling Git to point your current branch to the exact same commit as the remote main. Once you run this command, your local main is an exact clone of what's on origin. This two-step fetch and reset process is the cleanest, most direct way to "pull" and overwrite your local changes.
🌐
Quora
quora.com › How-do-I-force-git-pull-to-overwrite-local-files-1
How to force 'git pull' to overwrite local files - Quora
Answer (1 of 17): You can probably do [code]git stash git stash drop # deletes the latest changes on the stash [/code]However [code ]git reset HEAD —hard[/code] would be the proper way to do what you want. This resets your git workspace to the latest commit on the local branch, and discards ...
🌐
W3docs
w3docs.com › git
How to Force Git Pull to Override Local Files
This tutorial will show you how to force git pull in case of untracked files which will be overwritten. Find important tips to avoid unwanted mistakes.
🌐
Sentry
sentry.io › sentry answers › git › force `git pull` to overwrite local files
Force `git pull` to overwrite local files | Sentry
This command will save and store ... remote changes. To reapply the uncommitted work on top of the new commits, run git stash pop....
🌐
Peterdaugaardrasmussen
peterdaugaardrasmussen.com › 2023 › 03 › 03 › how-to-force-a-git-pull
Git - How to force a git pull and overwrite local changes
March 4, 2023 - We will then push a change and overwrite local uncommitted changes in the other. In short you are likely looking for these commands: git fetch origin master git reset --hard origin/master