If you want to overwrite only one file:

git fetch
git checkout origin/main <filepath>

If you want to overwrite all changed files:

git fetch
git reset --hard origin/main

(This assumes that you're working on main locally and you want the changes on the origin's main - if you're on a branch, or your project uses the old master main branch name rather than main, substitute that in instead.)

Answer from Amber on Stack Overflow
🌐
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
4 days ago - 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: To force a branch switch when untracked files are in the way:
Discussions

deployment - Git command to checkout any branch and overwrite local changes - Stack Overflow
You could follow a solution similar to "How do I force “git pull” to overwrite local files?": git fetch --all git reset --hard origin/abranch git checkout abranch More on stackoverflow.com
🌐 stackoverflow.com
Why does doing 'force checkout' to some previous commit destroy the file that isn't commited?
Instead we do git checkout -f 398d and all the changes get destroyed. Why it makes sense? Because that's exactly what is meant by "force", and what the -f flag does. Wouldn't it make more sense if instead we keep the uncommited text in case I switch to master branch again? If that's what you want, then you should just do git checkout 398d without the -f. It sounds like you just want -f to not exist... Why? What would the point of that be? Just don't use it if you don't want it. More on reddit.com
🌐 r/git
5
4
March 31, 2022
version control - How do I force "git pull" to overwrite local files? - Stack Overflow
How do I force an overwrite of local files on a git pull? My local repository contains a file of the same filename as on the server. error: Untracked working tree file 'example.txt' would be overwritten by merge ... basically, only do a pull from develop after the initial checkout -b. More on stackoverflow.com
🌐 stackoverflow.com
Stashing and force checkouts
git stash push should have stashed any changes to tracked files and reverted them to the same state as HEAD. Any untracked files will still be there though. You can stash them by adding -u to the stash command: git stash push -u. More on reddit.com
🌐 r/git
2
2
February 24, 2019
🌐
iO Flood
ioflood.com › blog › git-force-checkout-how-to-overwrite-local-modifications
Git Force Checkout | How To Overwrite Local Modifications
November 26, 2023 - In particular we focus on “forcing” checkouts, including how to, and pros and cons. If you’re new to Git or looking to deepen your understanding, you’re in the right place. Let’s embark on this journey! ‘Git checkout’ is a command in Git that allows developers to switch between different versions of a target entity, be it a file...
🌐
Git
git-scm.com › docs › git-checkout
Git - git-checkout Documentation
git checkout refuses when the wanted branch is already checked out or otherwise in use by another worktree. This option makes it check the branch out anyway. In other words, the branch can be in use by more than one worktree. ... Silently overwrite ignored files when switching branches.
🌐
Git Scripts
gitscripts.com › git-checkout-force-overwrite
Git Checkout Force Overwrite: A Quick Guide to Mastery
May 4, 2025 - ... Using `git checkout -f` comes with significant risks, most notably the potential for data loss. If you force checkout without committing or backing up, you will lose any uncommitted work permanently.
🌐
Brian Childress
brianchildress.co › git-force-overwrite-of-local-file-with-remote
GIT: Force Overwrite of Local File with Remote File - Brian Childress
Overwriting a single file · Update your local version of the remote repository, i.e. Origin · Checkout the file(s) you want to overwrite ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-force-checkout-in-git
How to Force Checkout in Git? - GeeksforGeeks
May 29, 2024 - git checkout --ours <file-path> ... of the app.js file. ... The -B flag is used to forcefully create a new branch based on the current HEAD, overwriting any existing branch with the same name....
🌐
Graphite
graphite.com › guides › git-force-checkout
Git force checkout - Graphite
Git force checkout refers to forcefully switching branches or restoring working tree files, potentially overwriting local changes.
🌐
Reddit
reddit.com › r/git › why does doing 'force checkout' to some previous commit destroy the file that isn't commited?
r/git on Reddit: Why does doing 'force checkout' to some previous commit destroy the file that isn't commited?
March 31, 2022 -

Let's say we have a text file with some text: boo. We commit that change and say it has a hash 398d. Now we make changes to that text and add 'foo' but we don't commit it yet. Instead we do git checkout -f 398d and all the changes get destroyed. Why it makes sense? Wouldn't it make more sense if instead we keep the uncommited text in case I switch to master branch again?

Top answer
1 of 4
19
Instead we do git checkout -f 398d and all the changes get destroyed. Why it makes sense? Because that's exactly what is meant by "force", and what the -f flag does. Wouldn't it make more sense if instead we keep the uncommited text in case I switch to master branch again? If that's what you want, then you should just do git checkout 398d without the -f. It sounds like you just want -f to not exist... Why? What would the point of that be? Just don't use it if you don't want it.
2 of 4
7
Force checkout is meant to forcefully switch state, which includes clobbering/discarding any changes. It's sort of like when you force push and it clobbers changes to the remote. The tool is working as designed in the scenario you describe. If you're wanting to keep uncommitted changes around without necessarily committing, consider git stash. This is the canonical way to temporarily save uncommitted changes for later, e.g. "I was on my feature branch, made a bugfix, then realized that I needed that bugfix in main/master instead". Unless I'm trying to diagnose a particularly tricky regression (using git bisect or the like) or I'm wanting to. compare behaviors between some state in the past and now, I, as a rule, will not check out previous commits. I certainly can, but it's harder to keep myself out of trouble, especially if I'm collaborating with others. I had a colleague once who was in the habit of checking out past commits, then making changes, then adding the changes to those commits. It was absolutely maddening to diagnose the wacky-ass errors he introduced into the codebase this way. My preference is always to treat past commits as immutable and sacred. So they were written, so they shall be, for ever and ever. If I need to make changes, I do so from the latest head of my current un-merged branch.
🌐
W3docs
w3docs.com › git
How to Force Git Pull to Override Local Files
Then, run the git reset command with the --hard flag to change all the files in the working tree for matching the files in origin/master (suppose, the name of remote is origin, which is by default).
🌐
Squash
squash.io › how-to-force-overwrite-during-git-merge
How to Force Overwrite During Git Merge - Squash Labs
October 28, 2023 - Another way to force overwrite during a git merge is by using the git reset and git checkout commands.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-override-local-files-with-git-pull
How to Overwrite Local Files with Git Pull
January 19, 2020 - It’s worth noting that it is ... checkout master git branch new-branch-to-save-current-commits git fetch --all git reset --hard origin/master...
🌐
Career Karma
careerkarma.com › blog › git › git your local changes to the following files would be overwritten by checkout solution
Git Your local changes to the following files would be overwritten by checkout Solution
December 1, 2023 - The Git “Your local changes to the following files would be overwritten by checkout” error occurs when you make changes on two branches without committing or stashing those changes and try to navigate between the branches.
🌐
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.
🌐
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 - Yes, use git checkout origin/main -- path/to/file.txt to overwrite a specific file with the remote version while keeping other local changes intact. “Git pull hard” isn’t an official command.
🌐
Quora
quora.com › How-do-I-force-Git-to-overwrite-local-files-on-pull
How to force Git to overwrite local files on pull - Quora
Answer (1 of 16): A2A - it seems as though you have quite a few answers already, but they all look wrong. It seems to me that you don’t really want git to overwrite your local files: you want to keep your changes. What you need to do is find a way to preserve your changes — you want to ...
🌐
Reddit
reddit.com › r/git › stashing and force checkouts
r/git on Reddit: Stashing and force checkouts
February 24, 2019 -

So I was checked out on a feature branch; I realized that I wanted to keep the progress but checkout to my development branch realy quickly. So I did git stash. Git says: Saved working directory and index state. So I assumed it got stashed. I thought all the modified files/new files would dissapear when 'stashed'; but guess not.

Then I forced checkout to development, thinking that all the changes I made would be removed. But it didn't. why is that? How would I accomplish my goal of removing every modified file I made in my feature 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 - However, there are situations where you may want to force “git pull” to overwrite local files without prompting for manual conflict resolution. This can be useful if you know that your local changes are obsolete and you want to replace them with the changes from the remote repository.