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
🌐
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:
Discussions

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. do your work, then push back in. ... Short answer: delete and re-create branch... More on stackoverflow.com
🌐 stackoverflow.com
how can I git checkout and overwirte branch by force? - Stack Overflow
I want to checkout branch and delete current exiting branch. eg git checkout -b --by-force $branch, so the branch will be based on current checkout branch; I always got $branch name is exist. I d... More on stackoverflow.com
🌐 stackoverflow.com
Share your best git alias you made.
ragequit = !sh -c 'git commit -am wip && shutdown -h now' More on reddit.com
🌐 r/git
27
89
April 20, 2024
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
🌐
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.
🌐
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 - 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....
🌐
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.
🌐
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....
Find elsewhere
🌐
TheLinuxCode
thelinuxcode.com › home › how to force checkout in git (safely): discard changes, reset branches, and resolve conflicts
How to Force Checkout in Git (Safely): Discard Changes, Reset Branches, and Resolve Conflicts – TheLinuxCode
February 1, 2026 - When you “checkout a branch,” Git is doing two separate things that are worth keeping distinct in your head: 1) It moves HEAD (and usually your current branch name) to point at a different commit. 2) It updates your working directory (and index) so the files on disk match that commit. That second part is where force comes in: Git protects you from overwriting files that have modifications you haven’t committed.
🌐
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 the steps below to overwrite ... with sensitive or critical data. Use the following syntax: git checkout -b [backup/feature-branch] [feature-branch]...
🌐
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 ...
🌐
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
You can maintain current local commits by creating a branch from your current branch before running git reset: git checkout <branch-name> git branch <new-branch-to-save-current-commits> git fetch --all git reset --hard origin/<branch-name>
🌐
Continuously Merging
articles.mergify.com › git-overwrite-local-branch-with-remote
Git Overwrite Local Branch with Remote Safely
August 26, 2025 - With the latest remote state fetched, you’re ready for the command that does the actual overwriting: git reset --hard. This is the powerhouse of the operation. It tells Git to do three things, all at once: Move your current branch pointer ...
🌐
TortoiseGit
tortoisegit.org › documentation › tortoisegit daily use guide
Checking Out A Working Tree (Switch to commit) – TortoiseGit – Documentation – TortoiseGit – Windows Shell Interface to Git
Check Overwrite working tree changes (force) will overwrite uncommitted changes in the working tree with the selected version. When you selected a remote branch, you can check Track in order to track the remote branch. When you open the push, pull or sync dialog, the remote branch will be ...
🌐
w3tutorials
w3tutorials.net › blog › how-do-i-overwrite-rather-than-merge-a-branch-on-another-branch-in-git
How to Overwrite a Git Branch with Another Branch (Instead of Merging) – Make Them Point to the Same Commit
First, switch to the branch you ... (if needed) git checkout feature-x # Switch back to the target branch · Run git reset --hard <source-branch> to force the target branch to match the source:...
🌐
Alpha Efficiency.™
alphaefficiency.com › git-force-checkout
How to Force Git Checkout | Alpha Efficiency.™
The correct syntax is git checkout -f or git checkout --force, but use these sparingly. Before forcing a checkout, consider safer alternatives like git stash to manage conflicting changes, or merging/rebasing instead.
Published   April 28, 2022
🌐
Coalesce
docs.coalesce.io › version control › git branches
Git Branches | Coalesce Documentation
For example, if you made changes to your branch, but run force checkout, it will overwrite the local changes if they differ making it match the remote branch.
🌐
Stack Overflow
stackoverflow.com › questions › 59255813 › how-can-i-git-checkout-and-overwirte-branch-by-force
how can I git checkout and overwirte branch by force? - Stack Overflow
But I think you instead want to make the name branch2 point to existing commit E, abandoning commits F-G-H, and also attach HEAD to the name branch2.
🌐
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.