Your local changes would be overwritten
This error occurs when you attempt to pull, merge, or rebase remote changes while you have unstaged local edits that conflict with the incoming commits.
Usually happens because:
- ☑ Uncommitted changes on files modified by incoming remote commits
- ☑ Attempting branch checkout with uncommitted edits on conflicting files
- ☑ Active merge/pull triggers file overwrite collision
🔍 Quick Checklist:
What is Your local changes would be overwritten?
Git blocks operations like merge, pull, or checkout if your working directory contains uncommitted edits on files that are also modified in the incoming commits. Git prevents the operation to safeguard your local work from being permanently overwritten. To resolve this, you must either commit your local changes, stash them temporarily, or discard them entirely before proceeding.
Common Causes
- Uncommitted local modifications: Editing files locally without committing or stashing them, then trying to merge or pull updates to those same files.
- Diverged tracking branch pull: Pulling remote modifications that overlap with your active workspace changes.
- Switching branches with uncommitted edits: Running 'git checkout' to switch branches when files you edited have different states in the target branch.
| Cause | Frequency |
|---|---|
| Uncommitted local edits on conflicted files | ⭐⭐⭐⭐⭐ |
| Switching branches with pending modifications | ⭐⭐⭐⭐ |
| Pulling remote master branch updates | ⭐⭐⭐⭐ |
Common Mistakes
- Running `git reset --hard` thinking it works like `git stash`. A hard reset is destructive and will permanently delete your uncommitted work.
- Forgetting to run `git stash pop` after a successful pull, leaving your local changes locked in the stash memory.
How to Fix
Git Operations & Verification
Store modifications in the Git stash stack, pull incoming commits, then pop the stash to apply local work.
# 1. Stash active uncommitted changes
$ git stash
Saved working directory and index state WIP on main...
# 2. Pull remote updates
$ git pull origin main
Updating a1b2c3d..e5f6g7h
# 3. Apply and pop stashed changes
$ git stash popPlatform Specific Fixes
Inspect uncommitted diffs before deciding to stash or discard.
# Show differences on modified tracked files
git diff src/app.jsBest Practices
- Commit your work in small, logical chunks frequently to avoid leaving files in an uncommitted state for long periods.
- Run `git status` to check your workspace before initiating pull or checkout commands.
Frequently Asked Questions (FAQ)
Q: Why does Git block my pull/merge?
Git does this to protect your unsaved work. If it proceeded with the merge, your local changes would be overwritten and lost forever.
Q: What does 'git stash' do?
'git stash' temporarily shelves (stores) your local modifications in a stack, returning your working directory to a clean state matching the HEAD commit.
Q: How do I restore my stashed changes?
Run 'git stash pop' to apply the last stashed changes and remove them from the stash stack.
Q: How do I discard all my local changes?
Run 'git reset --hard HEAD' to discard all uncommitted changes in tracked files and restore your working directory to match the last commit.