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

GitBEGINNERMEDIUMUpdated Dec 6, 2025· 449 views

This error occurs when Git detects uncommitted changes in your working directory that conflict with incoming changes from a merge. You need to either commit, stash, or discard your local changes before Git can proceed with the merge.

Quick fix

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

git status
  1. Check which files have local changes
  2. Option 1: Stash your changes (recommended)
  3. Option 2: Commit your changes first
  4. Option 3: Discard your local changes
git — error
git status
error: Your local changes to the following files would be overwritten by merge

What this error means

When you run `git pull` or `git merge`, Git attempts to combine the remote branch's changes with your local branch. However, if you have uncommitted modifications to files that are also modified in the incoming changes, Git cannot safely complete the merge without potentially losing your work. Git is being protective here—it refuses to overwrite your uncommitted changes because there's no way to recover them if they're lost. This is intentional behavior, not a bug. The error message lists exactly which files have conflicting local changes. This situation commonly occurs when: - You've made local edits but haven't committed them yet - A teammate pushed changes to the same files you're working on - You're switching branches or pulling updates in the middle of active development - CI/CD pipelines pull changes into a working directory that has been modified

Typical symptoms

  • git pull fails immediately without fetching or merging
  • git merge aborts before completing
  • The error lists specific filenames that have local modifications
  • git status shows modified files in your working directory
  • The operation is blocked even if local changes seem unrelated

Common causes

  1. Uncommitted local modifications conflict with incoming remote changes (most common)
  2. Staged changes that haven't been committed yet
  3. Local edits made after the last commit but before pulling
  4. Automatic file modifications (IDE config, generated files, package-lock.json)
  5. Interrupted previous merge leaving working directory in inconsistent state

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

1Check which files have local changes

First, understand what files Git is protecting:

bash
git status

This shows all modified, staged, and untracked files. The files listed in the error message will appear here as "modified" or "staged".

2Option 1: Stash your changes (recommended)

If you want to keep your local changes and apply them after the merge, use git stash:

bash
# Save your changes temporarily
git stash

# Now pull/merge will work
git pull

# Restore your changes
git stash pop

If there are conflicts when popping the stash, Git will notify you and you can resolve them manually. Your stashed changes are still safe in the stash list even if pop fails.

To see what's in your stash:

bash
git stash list
git stash show -p stash@{0}
3Option 2: Commit your changes first

If your changes are ready to be saved permanently, commit them before merging:

bash
git add .
git commit -m "WIP: Save local changes before merge"
git pull

If there are conflicts after pulling, Git will enter merge conflict resolution mode where you can address each conflict individually. This is often cleaner than resolving stash conflicts.

4Option 3: Discard your local changes

If you don't need your local changes, you can discard them:

Discard changes to specific files:

bash
git checkout -- path/to/file.txt

Discard all uncommitted changes:

bash
git checkout -- .

Or using the newer restore command (Git 2.23+):

bash
git restore path/to/file.txt
git restore .

After discarding, you can proceed with your merge or pull.

5Option 4: Use autostash with rebase

For a streamlined workflow, use autostash which automatically stashes before rebasing and pops after:

bash
git pull --rebase --autostash

This is equivalent to:

bash
git stash
git pull --rebase
git stash pop

To make this the default behavior:

bash
git config --global rebase.autoStash true
6Option 5: Hard reset (use with caution)

As a last resort, if you want to completely discard local changes and match the remote:

bash
git reset --hard HEAD
git pull

Warning: This permanently deletes all uncommitted changes. Only use this if you're certain you don't need your local modifications.

For an even more aggressive reset to match remote exactly:

bash
git fetch origin
git reset --hard origin/main

Advanced notes

### Dealing with Generated Files

If the conflict is in files like package-lock.json, .idea/, or other generated files that you don't manually edit:

bash
# Discard only the generated files
git checkout -- package-lock.json
git pull
npm install  # Regenerate lock file

Consider adding generated files to .gitignore if they shouldn't be tracked.

### Partial Stash

If you only want to stash specific files:

bash
git stash push -m "Stashing specific files" -- path/to/file1.txt path/to/file2.txt
git pull
git stash pop

### Stash Including Untracked Files

By default, git stash only saves tracked files. To include untracked files:

bash
git stash -u  # Include untracked files
git stash -a  # Include all files (untracked + ignored)

### Viewing Diff Before Deciding

Before choosing how to handle your changes, review what you've modified:

bash
# See what you changed locally
git diff

# See what's coming from remote
git fetch origin
git diff HEAD..origin/main

### CI/CD Pipelines

In CI/CD environments, this error often occurs when the pipeline workspace isn't clean. Add a cleanup step:

bash
git clean -fd  # Remove untracked files
git checkout -- .  # Discard modifications
git pull

Or configure your CI to always start with a fresh clone.

Frequently asked questions

What does "error: Your local changes to the following files would be overwritten" mean?
When you run git pull or git merge, Git attempts to combine the remote branch's changes with your local branch. However, if you have uncommitted modifications to files that are also modified in the incoming changes, Git cannot safely complete the merge without potentially losing your work. Git is being protective here—it refuses to overwrite your uncommitted changes because there's no way to recover them if they're lost.
How do I fix "error: Your local changes to the following files would be overwritten"?
This error occurs when Git detects uncommitted changes in your working directory that conflict with incoming changes from a merge. You need to either commit, stash, or discard your local changes before Git can proceed with the merge.
What causes "error: Your local changes to the following files would be overwritten"?
Uncommitted local modifications conflict with incoming remote changes (most common) Staged changes that haven't been committed yet Local edits made after the last commit but before pulling
Is the "error: Your local changes to the following files would be overwritten" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading