Skip to content
error: Your local changes would be overwritten by merge

error: Your local changes would be overwritten by merge

DodaTech 3 min read

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 merge while the working directory wasn’t clean.
  • You tried to git checkout a different branch that has changes to files you’ve modified.
  • You applied a patch or ran git stash pop that 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 pop

git 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 pull

Step 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 -fd

Step 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 back

Step 5: Check what’s preventing the operation

git status
# Shows modified, added, and deleted files
git diff --stat
# Shows what changed and by how much
Will git stash save my changes if I have untracked files?
By default, git stash only stashes tracked files. To include untracked files, use git stash -u (or --include-untracked). To also stash ignored files, use git stash -a (or --all). This is important if you’ve added new files that are being blocked by the merge.
What happens if I run git stash pop and get conflicts?
git stash pop applies the stash but doesn’t drop it if there are conflicts. You’ll need to resolve the conflicts manually (just like merge conflicts), stage the resolved files, run git stash drop manually, and then continue. Alternatively, use git stash apply instead of pop — it keeps the stash in case you need to re-apply.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro