error: Your local changes would be overwritten by merge
Git’s “Your local changes would be overwritten by merge” means uncommitted changes in your working directory conflict with changes from a merge or pull.
What It Means
Git protects your uncommitted work. When you run git merge, git pull, or git checkout, Git checks whether the operation would overwrite any files you’ve modified but haven’t committed. If the incoming changes touch the same files you’ve edited locally, Git refuses to proceed — it won’t silently destroy your work. You must either commit your changes, stash them temporarily, or discard them before the operation can proceed.
Why It Happens
- You started editing files but didn’t commit before running
git pull. - You ran
git mergewhile the working directory wasn’t clean. - You tried to
git checkouta different branch that has changes to files you’ve modified. - You applied a patch or ran
git stash popthat conflicts with working directory changes. - A pre-commit hook modified files and you tried to merge afterward.
How to Fix It
Step 1: Stash your changes (recommended)
Save your work temporarily and apply it after the merge:
git stash
git pull # or git merge
git stash popgit stash pop restores the stashed changes. If there are conflicts after popping, resolve them manually.
Step 2: Commit your changes
If your work is ready to save permanently:
git add .
git commit -m "WIP: save progress before merge"
git pullStep 3: Discard local changes (irreversible)
If you don’t need your uncommitted changes:
# Discard changes for a specific file
git checkout -- filename.rb
# Discard all uncommitted changes
git reset --hard HEAD
# Clean untracked files too
git clean -fdStep 4: Use a separate branch
If your changes are complex and not ready for commit:
git checkout -b temp-branch
git add .
git commit -m "Save work temporarily"
git checkout main
git pull
# Later, merge temp-branch backStep 5: Check what’s preventing the operation
git status
# Shows modified, added, and deleted files
git diff --stat
# Shows what changed and by how muchBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro