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

GitBEGINNERLOWUpdated Dec 6, 2025· 267 views

This error occurs when you try to switch branches while having uncommitted changes in files that differ between the current branch and the target branch. Git prevents the switch to avoid losing your work. You can resolve this by stashing, committing, or discarding your changes.

Quick fix

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

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

What this error means

When you run `git switch` (or `git checkout`) to change branches, Git needs to update your working directory to match the target branch. If you have uncommitted changes in files that also have different content on the target branch, Git cannot safely proceed—it would need to overwrite your local modifications with the target branch's version. Git prioritizes data safety over convenience. Rather than silently losing your work, it stops and asks you to handle the uncommitted changes first. This is a protective mechanism, not a bug. The error lists the specific files that would be overwritten, helping you identify which changes need to be handled before switching.

Typical symptoms

  • Cannot switch to another branch despite the branch existing
  • Error message lists one or more files that would be overwritten
  • The command works after running with --force but you lose your changes
  • Happens after editing files that you haven't committed yet
  • Issue does not occur when switching between branches where your modified files are identical

Common causes

  1. You have uncommitted changes in files that have different content on the target branch (most common)
  2. You started working on the wrong branch and need to move your changes
  3. You forgot to commit or stash before attempting to switch branches
  4. The target branch has modifications to the same files you've been editing locally
  5. Merge conflicts would occur between your changes and the target branch

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

1Review which files are blocking the switch

First, understand what's happening. Check which files have uncommitted changes:

bash
git status

Look at the files listed in the error message. These are the files that exist in different states on the target branch.

2Option 1: Stash your changes (recommended)

If you want to keep your changes and apply them later, use git stash:

bash
git stash
git switch <branch-name>

After switching, you can restore your changes:

bash
git stash pop

If you have multiple stashes or want to keep the stash after applying:

bash
git stash list              # View all stashes
git stash apply stash@{0}   # Apply without removing from stash

Note: If your stashed changes conflict with the new branch, you'll need to resolve merge conflicts after git stash pop.

3Option 2: Commit your changes first

If your changes are ready to be saved on the current branch:

bash
git add <files>
git commit -m "WIP: description of changes"
git switch <branch-name>

Or commit all tracked modified files:

bash
git add -u
git commit -m "WIP: save work before switching"
git switch <branch-name>

You can always amend or squash this commit later if needed.

4Option 3: Discard your changes

Warning: This will permanently delete your uncommitted work.

If you're certain you don't need the changes, you can discard them:

bash
# Discard changes in specific files
git checkout -- <filename>

# Or discard all uncommitted changes
git checkout -- .

# Then switch normally
git switch <branch-name>

Alternatively, force the switch (same effect—loses your changes):

bash
git switch --force <branch-name>
# or
git switch -f <branch-name>
5Option 4: Move changes to the target branch

If you started work on the wrong branch and want to move your changes to the target branch:

bash
git stash
git switch <target-branch>
git stash pop

If the changes apply cleanly, you're done. If there are conflicts, Git will mark them and you'll need to resolve them manually.

Alternative using a temporary branch:

bash
git stash branch <new-branch-name>

This creates a new branch from where you stashed, applies the stash, and drops it if successful.

Advanced notes

### Understanding When This Error Occurs

Git only blocks the switch when there's an actual conflict. If your modified files are identical on both branches (or don't exist on the target branch), Git allows the switch and carries your changes along.

### Using git switch vs git checkout

The git switch command (introduced in Git 2.23) is the modern way to change branches. The older git checkout command produces the same error:

bash
error: Your local changes to the following files would be overwritten by checkout

Both commands accept --force / -f to override the protection.

### Stash vs Commit: When to Use Which

Use stash when:
- Your changes are incomplete or experimental
- You need to quickly switch branches and come back
- You're not sure which branch the changes belong on

Use commit when:
- Your changes are complete enough to save
- You want a clear history of what was done
- You might need to reference or cherry-pick the changes later

### Handling Partial Changes

If you only want to stash some files:

bash
git stash push -m "description" -- path/to/file1 path/to/file2

Or interactively choose hunks to stash:

bash
git stash push -p

### The --merge Option

For complex situations, git switch --merge attempts a three-way merge between your changes, the current branch, and the target branch:

bash
git switch --merge <branch-name>

This can help in some cases but may result in merge conflicts that need resolution.

### Worktrees for Parallel Work

If you frequently need to work on multiple branches simultaneously, consider using Git worktrees:

bash
git worktree add ../project-feature feature-branch

This creates a separate working directory for the other branch, avoiding switch conflicts entirely.

Frequently asked questions

What does "error: Your local changes to the following files would be overwritten" mean?
When you run git switch (or git checkout) to change branches, Git needs to update your working directory to match the target branch. If you have uncommitted changes in files that also have different content on the target branch, Git cannot safely proceed—it would need to overwrite your local modifications with the target branch's version. Git prioritizes data safety over convenience.
How do I fix "error: Your local changes to the following files would be overwritten"?
This error occurs when you try to switch branches while having uncommitted changes in files that differ between the current branch and the target branch. Git prevents the switch to avoid losing your work. You can resolve this by stashing, committing, or discarding your changes.
What causes "error: Your local changes to the following files would be overwritten"?
You have uncommitted changes in files that have different content on the target branch (most common) You started working on the wrong branch and need to move your changes You forgot to commit or stash before attempting to switch branches
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