error: Your local changes to the following files would be overwritten by merge:
src/app.js
Please commit your changes or stash them before you merge.
You have uncommitted changes in files that Git needs to modify (from a pull, merge, or checkout). Git refuses to overwrite your work.
Fix 1: Stash your changes, then pull
git stash
git pull
git stash pop
This saves your changes, pulls the new code, then re-applies your changes on top. If there are conflicts, you’ll need to resolve them.
Fix 2: Commit your changes first
git add -A
git commit -m "WIP: save current work"
git pull
Then you can amend or squash the commit later if needed.
Fix 3: Discard your local changes (if you don’t need them)
# Discard changes in specific files
git checkout -- src/app.js
# Discard ALL uncommitted changes
git checkout -- .
# Nuclear option: reset everything
git reset --hard
git pull
⚠️ git reset --hard permanently deletes uncommitted changes. Make sure you don’t need them.
Fix 4: For checkout/branch switching
# ❌ Can't switch branches with uncommitted changes
git checkout feature-branch
# ✅ Stash first
git stash
git checkout feature-branch
git stash pop # Re-apply on the new branch