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.
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.
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.
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
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.
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