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 - By adding the -f or --force option to the ‘git checkout’ command, you can force Git to switch branches, discarding any uncommitted changes: ... Exercise caution! ‘Force checkout’ is a potent command, and it can easily result in lost work if not used properly.
Discussions

version control - How do I force "git pull" to overwrite local files? - Stack Overflow
The following version commits your local changes to a temporary branch (tmp), checks out the original branch (which I'm assuming is master) and merges the updates. You could do this with stash, but I've found it's usually easier to simply use the branch / merge approach. git checkout -b tmp git ... More on stackoverflow.com
🌐 stackoverflow.com
git - Force overwrite of local file with what's in origin repo? - Stack Overflow
My intention to take all the changes ... branch and commit to a branch in which I am working, the name of my branch is 'mybranch'. Then I first replaced my local changes which is I already pushed to my branch mybranch, then I have to pushed 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 ... More on stackoverflow.com
🌐 stackoverflow.com
How do I overwrite one branch with another branch?
Why not... make a new branch? More on reddit.com
🌐 r/git
23
42
May 20, 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
People also ask

Does git checkout overwrite uncommitted changes in the working directory?

Yes. git checkout -- replaces the files at that path with the source-branch versions, discarding any uncommitted local edits there. Commit or stash your work first if you need to keep it.

🌐
daehnhardt.com
daehnhardt.com › home › git survival guide › git checkout for overwriting directories from different branches
Git Checkout for overwriting directories from different branches
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 ...
Why does git checkout create new files in the target directory?

git checkout -- mirrors the source directory exactly, so files present in the source but missing in the destination are created. The commit output reports them, for example create mode 100744 scripts/publish/how_to.md.

🌐
daehnhardt.com
daehnhardt.com › home › git survival guide › git checkout for overwriting directories from different branches
Git Checkout for overwriting directories from different branches
🌐
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]...
🌐
Git
git-scm.com › docs › git-checkout
Git - git-checkout Documentation
Create a new branch named <new-branch>, start it at <start-point> (defaults to the current commit), and check out the new branch. You can use the --track or --no-track options to set the branch’s upstream tracking information. This will fail if there’s an error checking out <new-branch>, ...
🌐
Daehnhardt
daehnhardt.com › home › git survival guide › git checkout for overwriting directories from different branches
Git Checkout for overwriting directories from different branches
September 22, 2024 - Yes. git checkout <branch> -- <path>/ replaces the files at that path with the source-branch versions, discarding any uncommitted local edits there. Commit or stash your work first if you need to keep it. git checkout <source> -- <path>/ mirrors ...
🌐
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 - If your error is related to switching ... 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: ... If you're using the Tower Git client, you’ll notice that it helps ...
🌐
DataCamp
datacamp.com › tutorial › git-pull-force
Git Pull Force: How to Overwrite a Local Branch With Remote | DataCamp
August 6, 2024 - 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. This action will permanently delete all your local changes in that branch.
Find elsewhere
🌐
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 Scripts
gitscripts.com › git-checkout-force-overwrite
Git Checkout Force Overwrite: A Quick Guide to Mastery
May 4, 2025 - ... The `git checkout` command with the `--force` option allows you to switch branches and overwrite any local changes, ensuring your working directory matches the target branch exactly.
🌐
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.
🌐
DEV Community
dev.to › labex › how-to-resolve-local-changes-overwritten-by-checkout-26p2
How to Resolve Local Changes Overwritten by Checkout - DEV Community
November 25, 2024 - # Making local changes to a file echo "New content" >> README.md # Checking out a different branch git checkout feature/bug-fix · In the example above, if the README.md file has different content in the feature/bug-fix branch, your local changes will be overwritten.
🌐
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.
🌐
Reddit
reddit.com › r/git › how do i overwrite one branch with another branch?
r/git on Reddit: How do I overwrite one branch with another branch?
May 20, 2019 - ... Branches are merely pointers to commits. If you want to set one branch to point to the same commit as some other branch, use git reset. # Make sure your working tree is in a clean state git status # Check out the branch you want to change, e.g.
🌐
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 - Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force) allows overwriting local branches. It is always used with source and destination branches mentioned as parameters.
🌐
Continuously Merging
articles.mergify.com › git-overwrite-local-branch-with-remote
Git Overwrite Local Branch with Remote Safely
August 26, 2025 - Check out the branch again: git checkout your-branch-name · Git is smart. It sees you don't have a local branch with that name anymore, so it automatically creates a new one that tracks the remote counterpart. Simple as that. Pro Tip: The -D flag is a force-delete. If you tried using a lowercase -d, Git would stop you if the branch had unmerged changes...
🌐
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.
🌐
Atlassian
atlassian.com › git › tutorials › resetting checking out and reverting
Resetting, Checking Out & Reverting | Atlassian Git Tutorial
December 16, 2025 - ... Internally, all the above command ... to overwrite local changes, Git forces you to commit or stash any changes in the working directory that will be lost during the checkout operation....
🌐
codestudy
codestudy.net › blog › error-your-local-changes-to-the-following-files-would-be-overwritten-by-checkout
How to Fix 'Your Local Changes Would Be Overwritten by Checkout' Git Error When Switching Branches (Staging, Beta, Master) — codestudy.net
If your local changes are accidental or no longer needed, discard them to switch branches. Warning: This permanently deletes your changes—only use this if you’re sure you don’t need them! To discard changes to a single file (e.g., src/auth.js): git checkout -- src/auth.js # Overwrites the file with the last committed version