Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Your local changes would be overwritten by merge

Git is protecting your uncommitted work. This error means you have unsaved changes in files that the operation needs to update. Here are three safe ways to fix it.

Error explained

What this error means

When Git needs to update files that contain uncommitted changes, it refuses to proceed to protect your work. This is a safety mechanism, not a bug. You will see this during git pull, git checkout, or git merge.

Root causes

Why this happens

Pulling with uncommitted changes

You edited files locally but did not commit or stash them. When git pull tries to merge remote changes into those same files, Git blocks the operation to protect your work.

Switching branches with modified files

You have uncommitted changes in files that differ between branches. Git cannot switch without overwriting your modifications, so it stops and warns you.

Stash pop or apply conflicts

If you have modifications and try to apply a stash that touches the same files, Git warns that your current changes would be overwritten by the stash contents.

Three ways to fix it

How to fix it

Choose the option that fits your situation. Stashing is the safest when your work is not ready to be committed.

Option 1: Stash, operate, restore Recommended

Option 2: Commit your work first

Option 3: Discard local changes Destructive

Best practices

How to prevent this error

Commit or stash before pulling

Always commit or stash before git pull or switching branches. Make this a habit and you'll never see this error again.

Use git pull --autostash

The --autostash flag stashes before pulling and restores after. Set as default: git config --global rebase.autoStash true.

Check git status first

Run git status before any branch operation. If you see modified files, commit, stash, or discard before proceeding.

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about this Git error

Stop guessing, start understanding Git

GitQuest teaches you Git through hands-on investigations and real-world scenarios. Learn to handle errors with confidence.

Start learning