How to fix error: Your local changes to the following files would be overwritten by merge in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 221 views

This error occurs when running git stash apply or git stash pop, and Git detects uncommitted local changes that conflict with the stashed changes. Git refuses to proceed to prevent data loss.

Quick fix

Fixes error: Your local changes to the following files would be overwritten by merge

# Stage all current changes
git add .

# Now apply the stash
git stash apply

# Unstage if you don't want to commit yet
git reset HEAD
  1. Stage your current changes first
  2. Commit your current changes
  3. Discard current changes if not needed
  4. Create a branch from the stash
git โ€” error
# Stage all current changes
git add .
# Now apply the stash
git stash apply
# Unstage if you don't want to commit yet
git reset HEAD
error: Your local changes to the following files would be overwritten by merge

What this error means

When you run `git stash apply` or `git stash pop`, Git attempts to merge the stashed changes back into your working directory. However, if you have uncommitted modifications to files that are also modified in the stash, Git cannot safely merge them without potentially overwriting your current work. This is a safety mechanism. Git is telling you that applying the stash would overwrite uncommitted changes in your working directory. Rather than silently destroying your work, Git stops and asks you to deal with the conflicting changes first. The error typically appears when you stashed some changes, then made additional modifications to the same files (or received them via pull/checkout), and now want to restore your stash. Git sees that both your current working directory and the stash have changes to the same files, and it cannot automatically reconcile them.

Typical symptoms

  • git stash apply fails with "Your local changes to the following files would be overwritten by merge"
  • git stash pop fails with the same error and the stash remains in the stash list
  • Error message lists specific files that have conflicting changes
  • The command suggests committing or stashing changes before proceeding

Common causes

  1. You have uncommitted changes to files that are also modified in the stash you are trying to apply
  2. You made additional edits to files after stashing and before applying the stash
  3. You switched branches and the new branch has modifications to the same files as the stash
  4. A git pull introduced changes to files that conflict with your stashed changes
  5. Untracked files in your working directory would be created by the stash apply

How to fix "error: Your local changes to the following files would be overwritten by merge"

1Stage your current changes first

The simplest solution is to stage your current changes, which allows git stash apply to proceed:

bash
# Stage all current changes
git add .

# Now apply the stash
git stash apply

# Unstage if you don't want to commit yet
git reset HEAD

This works because staging moves your changes to the index, giving Git a clean working tree to apply the stash to.

2Commit your current changes

If your current changes are ready to be committed, commit them first:

bash
# Commit current work
git add .
git commit -m "WIP: save current progress"

# Apply the stash
git stash apply

# Optional: reset the WIP commit but keep changes
git reset --soft HEAD~1

This preserves both sets of changes and lets you decide how to combine them.

3Discard current changes if not needed

If your current uncommitted changes are not important, you can discard them:

bash
# WARNING: This permanently discards uncommitted changes
git checkout .

# Now apply the stash
git stash apply

Caution: Only use this if you are certain you don't need your current changes. This action cannot be undone.

4Create a branch from the stash

Use git stash branch to create a new branch with your stashed changes applied cleanly:

bash
# Create a new branch from the stash
git stash branch my-stashed-work

# This creates a branch at the commit where you originally stashed,
# applies the stash, and drops it from the stash list

This is especially useful when your current branch has diverged significantly from when you created the stash.

5Force apply using patch

As a last resort, you can force the stash to apply using a patch:

bash
# Show stash as a patch and apply it
git stash show -p | git apply

# Or with the 3-way merge option for conflict markers
git stash show -p | git apply --3way

The --3way option will create conflict markers in files where automatic merge isn't possible, allowing you to resolve conflicts manually.

Advanced notes

### Understanding Stash Internals

A stash in Git is actually a special commit that stores the state of your working directory and index. When you run git stash apply, Git performs a three-way merge between:
1. The commit where the stash was created
2. The current HEAD
3. The stash contents

This merge can fail when there are uncommitted changes, because Git has no committed state to use as a basis for merging your current changes.

### Stash Apply vs Stash Pop

- git stash apply: Applies the stash but keeps it in the stash list
- git stash pop: Applies the stash and removes it from the list (only if successful)

When either command fails with conflicts, the stash is NOT removed from the list, so your stashed work is safe.

### Handling Untracked Files

If the error is about untracked files, the stash may have been created with git stash -u or git stash --include-untracked. In this case, you may need to move or delete the conflicting untracked files before applying.

### Using --index Flag

The --index flag attempts to reinstate the staged state from when you created the stash:

bash
git stash apply --index

This can sometimes work when the regular apply fails, particularly if the conflicts are in the staging area rather than the working directory.

Frequently asked questions

What does "error: Your local changes to the following files would be overwritten" mean?
When you run git stash apply or git stash pop, Git attempts to merge the stashed changes back into your working directory. However, if you have uncommitted modifications to files that are also modified in the stash, Git cannot safely merge them without potentially overwriting your current work. This is a safety mechanism.
How do I fix "error: Your local changes to the following files would be overwritten"?
This error occurs when running git stash apply or git stash pop, and Git detects uncommitted local changes that conflict with the stashed changes. Git refuses to proceed to prevent data loss.
What causes "error: Your local changes to the following files would be overwritten"?
You have uncommitted changes to files that are also modified in the stash you are trying to apply You made additional edits to files after stashing and before applying the stash You switched branches and the new branch has modifications to the same files as the stash
Is the "error: Your local changes to the following files would be overwritten" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading