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 

That would involve only one fetch.

With Git 2.23+, git checkout is replaced here with git switch (presented here) (still experimental).

git switch -f $branch

(with -f being an alias for --discard-changes, as noted in Jan's answer)

Proceed even if the index or the working tree differs from HEAD.
Both the index and working tree are restored to match the switching target.


If you do not want to switch branch, but only restore a folder from another branch, then git restore is the other command which replaces the old obsolete and confusing git checkout.
I presented git restore here.

git restore --source=anotherBranch --staged] [--worktree -- aFolder
# or, shorter:
git restore -s anotherBranch -SW -- aFolder
Answer from VonC on Stack Overflow
🌐
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.
Discussions

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
git - Force overwrite of local file with what's in origin repo? - Stack Overflow
Then I first replaced my local ... this command to my branch. Force push command is ... It will push whatever changes I got from 'feature/branchname' branch to my 'mybranch'. ... After running into this problem, I finally tried git checkout --force and it did exactly ... More on stackoverflow.com
🌐 stackoverflow.com
"The following untracked working tree files would be overwritten by checkout"
Here is a sequence for illustration: $ mkdir untracked $ cd untracked $ git init $ date > DATE $ git add DATE $ git commit -m "Adding DATE file" $ date > TIME $ git checkout -b has-time $ git add TIME $ git commit -m "Adding TIME file" $ git checkout - # go back to original branch (main) $ ls TIME Result: No such file, because it is not in the original (main) branch $ date > TIME $ git checkout has-time Result: error: The following untracked working tree files would be overwritten by checkout: TIME Please move or remove them before you switch branches. Aborting More on reddit.com
🌐 r/git
10
2
August 2, 2024
🌐
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 complex code repositories with multiple branches and frequent commits, ‘force checkout’ can be a formidable tool. It enables swift switching between branches, discarding unwanted changes, and maintaining a clean working directory. However, remember to exercise caution with this command. It’s a powerful tool, but with great power comes great responsibility. As previously discussed, the ‘-f’ or ‘–force’ option can be paired with ‘git checkout’ to force Git to switch branches, discarding any uncommitted changes:
🌐
Git Scripts
gitscripts.com › git-checkout-force-overwrite
Git Checkout Force Overwrite: A Quick Guide to Mastery
May 4, 2025 - Git Checkout --Force: Mastering ... ... Here, the `-f` flag stands for "force," telling Git to overwrite any existing changes in your current working directory with the content from the specified branch....
🌐
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.
🌐
Git
git-scm.com › docs › git-checkout
Git - git-checkout Documentation
Using --recurse-submodules will update the content of all active submodules according to the commit recorded in the superproject. If local modifications in a submodule would be overwritten the checkout will fail unless -f is used. If nothing (or --no-recurse-submodules) is used, submodules ...
🌐
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 - If your error is related to switching branches rather than pulling, you might be using git checkout -f or git switch --force.
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....
🌐
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.
🌐
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 ·
🌐
RTEE Tech
blog.rteetech.com › home › development › git force checkout: safely switch branches & discard changes
Git Force Checkout: Safely Switch Branches & Discard Changes
June 5, 2025 - `git checkout` checks out a branch or file while preserving local changes. Adding the `-f` flag forcefully overwrites local modifications.
🌐
Atlassian
jira.atlassian.com › browse › SRCTREEWIN-441
As a user, I want to force checkout a remote branch and ...
When checking out a new branch from a remote, there should be an option to force/override the current local branch. This would allow a fresh copy without pull/rebase. ... git -c diff.mnemonicprefix=false -c core.quotepath=false checkout -b develop --track origin/develop fatal: A branch named 'develop' already exists.
🌐
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 - You must explicitly use git reset --hard or git pull --force to overwrite local changes. Create a backup branch first: git checkout -b backup, then switch back to main: git checkout main, and finally force pull: git reset --hard origin/main.
🌐
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.
🌐
DataCamp
datacamp.com › tutorial › git-pull-force
Git Pull Force: How to Overwrite a Local Branch With Remote | DataCamp
August 6, 2024 - There’s a misconception that this is achieved using git pull --force. This is incorrect because git pull --force combines git fetch --force and git merge. Therefore, it attempts to merge the local changes with the remote changes, not overwriting them.
🌐
Squash
squash.io › how-to-force-overwrite-during-git-merge
How to Force Overwrite During Git Merge - Squash Labs
October 28, 2023 - 3. Once the branch is reset, use the git checkout command to apply the changes from the branch you want to overwrite from: ... In the above command, other_branch is the branch from which you want to overwrite changes.
🌐
W3docs
w3docs.com › git
How to Force Git Pull to Override Local Files
git checkout <branch-name> git branch <new-branch-to-save-current-commits> git fetch --all git reset --hard origin/<branch-name>
🌐
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.