⚠ 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
Learn how to force `git pull` in Git to overwrite local changes safely using `git reset --hard` and `git stash`. Understand use cases, risks, and best practices.
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 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
How do you prevent a local file from being overwritten by a more recent remote file?
If you run git pull, by default you'll overwrite all files, even those you most definitely do not want to be modified (e.g., configuration files with database details) that's not true, it will tell you error: Your local changes to the following files would be overwritten by merge: and halt the pull/merge. In general, if you have files that are specific to the machine you are on: don't commit them to the repo, gitignore them and have an example file. That way it will never overwrite these files. If you've already committed these files, you can remove them from the repo while keeping the local with git rm --cached . More on reddit.com
🌐 r/git
14
4
May 29, 2018
Pycharm + GitHub: can't push, pull or merge - made changes in both places
You likely have a commit on your local branch that isn't on the remote branch AND a commit on the remote branch that isn't on the local branch. This is tricky to resolve, so generally people avoid committing to a single branch in more than one place. I'm assuming all this is on your main/master branch and that you're already on it. use git log (exit with the Q key) to track down all the commits that are on your local branch and not on your GitHub remote branch. Write down their SHAs (the funny number+letter combinations, they are unique identifiers of commits). git reset --hard - you can use git log to find it as well git pull - this should fast-forward your main to match the remote git cherry-pick - repeat for all commits you wrote down. You might have to fix conflicts as you do this, google to find out how. More on reddit.com
🌐 r/learnprogramming
10
2
September 6, 2023
People also ask

How do I force git pull to overwrite local files?
There is no single git pull --force command; to forcibly overwrite your local branch with the remote state, you use a two-step approach: first fetch, then hard-reset. Run git fetch origin to download the latest remote state, then git reset --hard origin/ to move your local branch pointer to exactly match the remote, discarding all local commits and staged changes. If you also have untracked files you want to remove, follow up with git clean -fd to delete them — note this is permanent and cannot be undone. Before executing these destructive commands, run git status and git stash push to preserv
🌐
git-tower.com
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 ...
I used git stash but now I'm getting merge conflicts. Help!
Merge conflicts can occur when reapplying stashed changes on top of new commits. You'll need to resolve the conflicts manually, then `git add` and `git commit` to finish applying the stash.
🌐
blog.openreplay.com
blog.openreplay.com › openreplay blog › git force pull: how to safely overwrite local changes and sync with remote
Git Force Pull: How to Safely Overwrite Local Changes and Sync ...
How do I undo a git reset --hard?
You can usually recover from an accidental `git reset --hard` using `git reflog` to find the commit you were on before the reset, then `git reset --hard ` to that commit hash.
🌐
blog.openreplay.com
blog.openreplay.com › openreplay blog › git force pull: how to safely overwrite local changes and sync with remote
Git Force Pull: How to Safely Overwrite Local Changes and Sync ...
🌐
Reddit
reddit.com › r/git › how to overwrite local changes from remote repository?
r/git on Reddit: How to overwrite local changes from remote repository?
March 11, 2022 -

Basically I want to clone a repository, regardless of whether that repository exists locally or not. If there is a local version I want it overwritten. I don't to synchronise any local changes to the master repo, I want a one directional flow of information from the remote repository to the local one. Seems like it should be straightforward, but I can't find an easy way to do this. My solution is to delete the folder and re-clone it every time I want to update it, but that seems wrong. Is there a command for this? something like git clone -force repositorylink

🌐
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 - This way, running git pull_force will overwrite the local changes, while git pull_stash will preserve them.
🌐
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....
Find elsewhere
🌐
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 ...
🌐
Better Stack
betterstack.com › community › questions › how-to-force-git-pull
How Do I Force “Git Pull” to Overwrite Local Files? | Better Stack Community
To force git pull to overwrite local files, you can use the git reset command along with the --hard option after pulling changes.
🌐
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
5 days 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.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 4413534536722-How-do-I-force-git-pull-to-overwrite-local-files
How do I force "git pull" to overwrite local files? – IDEs Support (IntelliJ Platform) | JetBrains
December 22, 2021 - How do I force Git to overwrite them? The person is a designer - usually, I resolve all the conflicts by hand, so the server has the most recent version that they just need to update on their computer. Thanks. ... Hello Mobelaris They don't have these files are not included in git. So they can right click on these files - Git -> Add The go to Commit tab - Right click on them -> Shelve changes And after that try to update/pull
🌐
OpenReplay
blog.openreplay.com › openreplay blog › git force pull: how to safely overwrite local changes and sync with remote
Git Force Pull: How to Safely Overwrite Local Changes and Sync with Remote
February 10, 2025 - While git pull --force may sound like the right command, it’s better to use git fetch and git reset --hard to overwrite local changes and sync with the remote repo. Just be careful, as reset --hard and clean -fd are irreversible!
🌐
DataCamp
datacamp.com › tutorial › git-pull-force
Git Pull Force: How to Overwrite a Local Branch With Remote | DataCamp
August 6, 2024 - In this article, we learn that these are different things. If you're new to Git, consider reading our Git push and pull tutorial first. We can overwrite our local state with the remote state by using the commands listed below, substituting <branch_name> with the name of your branch.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-force-git-pull-to-overwrite-local-files
How to Force git pull to Overwrite Local Files | Saturn Cloud Blog
May 1, 2026 - In most cases, this is the desired behavior because it allows you to review and modify the changes before merging them into your local branch. However, there are situations where you may want to force “git pull” to overwrite local files without prompting for manual conflict resolution.
🌐
Flexiple
flexiple.com › git › git-pull-force
Git Pull Force – How to Overwrite Local Changes With Git - Flexiple
Confirm the changes by running ... forcing a pull, preventing irreversible loss. Using force pull only when absolutely necessary, as it can overwrite local developments....
🌐
GitProtect.io
gitprotect.io › strona główna › how to use git pull force to overwrite local files
How to Use Git Pull Force to Overwrite Local Files - Blog | GitProtect.io
September 17, 2024 - Git doesn’t have a direct ‘git pull –force’ command, but you can achieve a similar effect by using ‘git fetch’ followed by ‘git reset –hard origin/main’ to overwrite a local branch.
🌐
Continuously Merging
articles.mergify.com › git-overwrite-local-branch-with-remote
Git Overwrite Local Branch with Remote Safely
August 26, 2025 - In these moments, the best move is a clean slate. The quickest way to force your local branch to be an exact copy of the remote is by running git fetch origin followed by git reset --hard origin/your-branch-name.
🌐
Sentry
sentry.io › sentry answers › git › force `git pull` to overwrite local files
Force `git pull` to overwrite local files | Sentry
When I run git pull, the command fails with an error message indicating that local files will be overwritten.
🌐
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?

🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to overwrite local branch with remote in git
How to Overwrite Local Branch with Remote in Git
February 4, 2026 - Follow this step-by-step tutorial and learn two different methods to overwrite a local branch with a remote in Git.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-override-local-files-with-git-pull
How to Overwrite Local Files with Git Pull
January 19, 2020 - If you feel the need to discard all your local changes and just reset/overwrite everything with a copy from the remote branch, then you should follow this guide. Important: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven’t been pushed will be lost. If you have any files that are not tracked by Git (e.g.
🌐
TecAdmin
tecadmin.net › force-overwrite-local-files-git-pull
How to Force Overwrite Local Files on Git Pull – TecAdmin
April 26, 2025 - The simplest way to force overwrite local files on Git pull is to use the --force option.