Git: "Your Local Changes to the Following Files Would Be Overwritten"

The operation would stomp uncommitted changes in the affected files. Git refuses rather than guessing. Choose deliberately: stash (keep them), commit (keep them properly), or discard (lose them) — the three moves cover every case.

What you'll see

Root causes

Uncommitted edits colliding with the incoming operation

A checkout/merge needs to change files you've modified but not committed. Git protects them by refusing. git status shows exactly which files are the conflict.

The sneaky case: line-ending or smudge filter churn

Files you never touched appear modified (CRLF rewrites, filters, permission masks): the same refusal fires on files with no real edits. git diff reveals phantom-vs-real changes immediately.

Fix it

  1. See what's actually dirty
    git status --short ; git diff   # phantom changes (you never edited) -> filter/line-ending issue, not stash material
  2. Keep the changes: stash, operate, restore
    git stash push -m 'before merge' && git pull && git stash pop   # pop after the operation completes
  3. Keep them properly: commit first
    git add -A && git commit -m 'wip' && git pull --rebase
  4. Deliberately discard (irreversible)
    git checkout -- <files>   # or restore: git restore <files> ; whole-tree: git reset --hard HEAD (drops ALL uncommitted work)

Field note

stash is the safe universal: it survives the operation, pops afterward, and conflicts (if any) resolve like merge conflicts. It never loses work by itself. git reset --hard answers this error but answers several OTHER questions destructively too — scope it, don't reflex it.

Common questions

Why does git refuse when the incoming changes don't touch my edited files?

It doesn't — the refusal lists only files the operation would rewrite. If the list surprises you, check git diff for phantom modifications (line endings, filters) — those need a renormalize fix, not a stash.

What happens if stash pop conflicts?

It becomes a normal merge conflict in your working tree: resolve, add, and git stash drop. The stash itself stays intact until you drop it — nothing is lost by the conflict.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.