If you want remove all local changes - including files that are untracked by git - from your working copy, simply stash them:

git stash push --include-untracked

If you don't need them anymore, you now can drop that stash:

git stash drop

If you don't want to stash changes that you already staged - e.g. with git add - then add the option --keep-index. Note however, that this will still prevent merging if those staged changes collide with the ones from upstream.


If you want to overwrite only specific parts of your local changes, there are two possibilities:

  1. Commit everything you don't want to overwrite and use the method above for the rest.

  2. Use git checkout path/to/file/to/revert for the changes you wish to overwrite. Make sure that file is not staged via git reset HEAD path/to/file/to/revert.

Answer from Daniel Hilgarth on Stack Overflow
🌐
DEV Community
dev.to › ajeetraina › error-your-local-changes-to-the-following-files-would-be-overwritten-by-merge-4hhm
error: Your local changes to the following files would be overwritten by merge - DEV Community
June 14, 2024 - This error message occurs when you try to use git merge but there are uncommitted changes in your local repository that conflict with the incoming changes from the remote branch.
Discussions

Error: Your local changes to the following files would be overwritten by merge
What commands do I need to follow to allow my LibreNMS to update? Thanks git pull Updating f9a379fa3..9635f88c0 error: Your local changes to the following files would be overwritten by merge: includes/polling/functions.inc.php Please commit your changes or stash them before you merge. Aborting More on community.librenms.org
🌐 community.librenms.org
0
0
April 12, 2021
Moodle in English: Your local changes to the following files would be overwritten by merge: | Moodle.org
Learn about Moodle's products, like Moodle LMS or Moodle Workplace, or find a Moodle Certified Service Provider. Moodle.com · Our social network to share and curate open educational resources. MoodleNet More on moodle.org
🌐 moodle.org
May 10, 2022
Update not working: error: Your local changes to the following files would be overwritten by merge: package-lock.json Please commit your changes or stash them before you merge.
What happened? When i try to update I get a error: error: Your local changes to the following files would be overwritten by merge: package-lock.json Please commit your changes or stash them before ... More on github.com
🌐 github.com
3
March 13, 2023
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
🌐
Jam
jam.dev › blog › git-your-local-changes-would-be-overwritten-by-merge
Fixing 'error:0308010c:digital envelope routines::unsupported' Error - Troubleshooting Guide
October 3, 2024 - You might have run into the error "Your local changes to the following files will be overwritten by merge" which occurs due to the version control mechanism that Git has.
🌐
Medium
medium.com › @iam.davidheart › how-to-fix-git-error-your-local-changes-to-the-following-files-will-be-overwritten-by-merge-d7341e7bdff1
How to fix Git Error ‘Your local changes to the following files will be overwritten by merge’ | by David Heart | Medium
December 6, 2019 - If merge doesn’t seem like a viable option for you, consider doing a rebase. Rebasing is the process of moving or combining a sequence of commits to a new base commit. In the case of rebasing, change the code to: git stash git pull --rebase origin master git stash pop · If you want to make changes to specific parts of the code and don’t want to replace everything, you can commit everything that you don’t want to overwrite and then follow method 3.
🌐
MiniTool
minitool.com › home › news › fix git error – your local changes would be overwritten by merge
Fix Git Error - Your Local Changes Would Be Overwritten by Merge - MiniTool
December 12, 2024 - If you have modified files that also have modifications in the remote repository, you may receive the “your local changes to the following files would be overwritten by merge” error message.
🌐
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 - You might expect that git pull --force would force Git to overwrite your local changes. It does not. The --force flag is passed down to git fetch, not git merge. It allows Git to update your local tracking references even when the remote history has been rewritten (e.g., after someone ran git push --force on the remote). ... It simply allows the fetch step to handle non-fast-forward ref updates. To actually overwrite local files, follow the steps below.
Find elsewhere
🌐
Career Karma
careerkarma.com › blog › git › git your local changes to the following files would be overwritten by merge solution
Git Your local changes to the following files would be overwritten by merge Solution
December 1, 2023 - The “Your local changes to the following files would be overwritten by merge” error occurs when you try to pull a remote repository to your local machine whose contents conflict with the contents of your local version of the repository.
🌐
LibreNMS Community
community.librenms.org › t › error-your-local-changes-to-the-following-files-would-be-overwritten-by-merge › 15450
Error: Your local changes to the following files would be overwritten by merge - LibreNMS Community
April 12, 2021 - Thanks git pull Updating f9a379fa3..9635f88c0 error: Your local changes to the following files would be overwritten by merge: includes/polling/functions.inc.php Please commit your changes or stash them before you merge.
🌐
Appuals
appuals.com › home › linux › linux troubleshooting
Fix: Local Changes to the Following Files Will Be Overwritten
October 22, 2024 - When you see the “Local changes to the following files will be overwritten” error in Git, it means Git is stopping you from pulling or switching branches because you have uncommitted changes that would conflict with new updates.
🌐
Daehnhardt
daehnhardt.com › home › git survival guide › preserve your local changes on git pull
Preserve your local changes on Git Pull - Daehnhardt
August 2, 2023 - The Git message “error: Your ... merge” indicates that you have some uncommitted changes in your working directory, and Git cannot perform the merge operation because those changes would be lost or overwritten during the merge process...
🌐
LabEx
labex.io › tutorials › git-how-to-address-error-your-local-changes-would-be-overwritten-by-merge-in-git-417548
How to address 'error: Your local changes would be overwritten by merge' in Git | LabEx
Make sure your team knows which files you're working on to avoid simultaneous changes to the same files. For complex merge conflicts, consider using GUI tools: ## List available GUI merge tools (in a real environment) ## git mergetool --tool-help ## In our case, let's just display what merge tools are typically available echo "Common merge tools: meld, kdiff3, vimdiff, vscode" By following these best practices, you can significantly reduce the occurrence of merge conflicts and the "Your local changes would be overwritten by merge" error in your Git workflows.
🌐
Moodle
moodle.org › mod › forum › discuss.php
Moodle in English: Your local changes to the following files would be overwritten by merge: | Moodle.org
May 10, 2022 - Instead, use .git/info/exclude and add new records there as # needed. # # Example: if you deploy a contributed plugin mod/foobar into your site, put # the following line into .git/info/exclude file in your Moodle clone: # /mod/foobar/ # # See gitignore(5) man page for more details
🌐
GitHub
github.com › Koenkk › zigbee2mqtt › issues › 17030
Update not working: error: Your local changes to the following files would be overwritten by merge: package-lock.json Please commit your changes or stash them before you merge. · Issue #17030 · Koenkk/zigbee2mqtt
March 13, 2023 - (use "git pull" to update your ... following files would be overwritten by merge: package-lock.json Please commit your changes or stash them before you merge....
Author   Koenkk
🌐
GitHub
github.com › Koenkk › zigbee2mqtt › issues › 15907
Cant update to latest code "error: Your local changes to the following files would be overwritten by merge" · Issue #15907 · Koenkk/zigbee2mqtt
January 3, 2023 - [new tag] 1.29.0 -> 1.29.0 Updating 52e545f..dddce57 error: Your local changes to the following files would be overwritten by merge: .github/workflows/ci.yml .github/workflows/stale.yml .github/workflows/update_deps.yml .github/workflows/update_frontend.yml .github/workflows/update_zh.yml .github/workflows/update_zhc.yml docker/Dockerfile lib/controller.ts lib/extension/bridge.ts lib/extension/configure.ts lib/extension/externalExtension.ts lib/extension/frontend.ts lib/extension/groups.ts lib/extension/homeassistant.ts lib/extension/networkMap.ts lib/extension/otaUpdate.ts lib/state.ts lib/ty
Author   Koenkk
🌐
Reddit
reddit.com › r/git › unable to pull and merge branches
r/git on Reddit: Unable to pull and merge branches
March 21, 2023 -

I am in my Docker local and am unable to pull my branch due to the error that I have files that conflict with the remote - however it is not giving me the option to merge the files. The below shell operation will clarify my issue - please help me how to merge changes made to remote into local:

root@c3c03a8f5468:/var/www# git status
On branch barber
Your branch is behind 'origin/barber' by 4 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean
root@c3c03a8f5468:/var/www# git pull origin
Updating 2a204e5..9aca606
error: Your local changes to the following files would be overwritten by merge:
	resources/js/app.js
	vite.config.js
Please commit your changes or stash them before you merge.
Aborting
root@c3c03a8f5468:/var/www# git stash
No local changes to save
root@c3c03a8f5468:/var/www# git pull origin
Updating 2a204e5..9aca606
error: Your local changes to the following files would be overwritten by merge:
	resources/js/app.js
	vite.config.js
Please commit your changes or stash them before you merge.
Aborting
🌐
Atlassian Support
support.atlassian.com › bamboo › kb › merging-git-lfs-repository-failing-due-to-local-changes
Merging Git LFS repository failing due to local changes | Bamboo | Atlassian Support
April 16, 2025 - Merge command error: ... Your local changes to the following files would be overwritten by merge: <list of files> Please commit your changes or stash them before you merge....