Skip to content
FR
  1. LuzineDebug
  2. Git & GitHub
  3. error: Your local changes to the following files…
Git & GitHub Beginner ≈ 5 min to fix

Fix "Your local changes to the following files would be overwritten by merge" in Git

Error message
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.
Aborting
  • error: Your local changes to the following files would be overwritten by checkout:
  • error: The following untracked working tree files would be overwritten by merge: config/local.json Please move or remove them before you merge.
  • error: Your local changes would be overwritten by cherry-pick.
  • error: cannot pull with rebase: You have unstaged changes.
  • error: Your local changes to the following files would be overwritten by switch:
In short

You have uncommitted changes in files that the git pull (or merge, checkout) needs to modify, and Git refuses to overwrite them. Put them aside with git stash, pull, then git stash pop, or commit them first; git pull --rebase --autostash does it all in one command.

Be the first to confirm this fix

What this error means

A merge, pull, checkout or cherry-pick rewrites the files in your working copy to match the new commit. If one of those files has local changes that are not in any commit, overwriting them would lose them for good. So Git checks before starting, lists the affected files and stops (Aborting) without touching anything: your repository is exactly as it was. The "untracked working tree files" variant means an untracked file on your side has the same name as a file the remote commit adds.

Common causes

  1. Uncommitted work in progress on a file a teammate also changed and pushed.
  2. File changed automatically: package-lock.json after npm install, a config file rewritten by the IDE or a build tool.
  3. Untracked file at the same path as a file newly added to the repository (e.g. a .env.example or a config/local.json you had created by hand).
  4. Line endings or file mode changed: core.autocrlf or a chmod make files appear modified even though you did not edit them.

Step-by-step fix

  1. See what is modified

    Look at the list and the content of the changes to decide whether you want to keep them.

    bash
    git status
    git diff src/app.js
  2. Option 1: commit, then pull

    If the work is ready, commit it, then fetch the remote and replay your commit on top.

    bash
    git add src/app.js
    git commit -m "Update app"
    git pull --rebase
  3. Option 2: put aside with stash

    The stash saves your changes, you pull, then you reapply them. -u also includes untracked files. If git stash pop causes a conflict, the stash is not deleted: resolve the conflict, then git stash drop.

    bash
    git stash push -u -m "wip before pull"
    git pull
    git stash pop
  4. Option 3: all in one command

    --autostash does the stash, the pull and the pop for you. You can enable it by default for rebases and merges.

    bash
    git pull --rebase --autostash
    # make it the default
    git config --global rebase.autoStash true
    git config --global merge.autoStash true
  5. Option 4: discard the local changes

    Only if you are sure you do not need them: git restore resets the file to the last committed version, and what you wrote is lost for good. When in doubt, prefer the stash.

    bash
    git restore src/app.js
    git pull
  6. Untracked files case

    Move or rename the blocking file, pull, then compare both versions. If you want to clean up, first preview what would be deleted with git clean -n: git clean -f deletes for good.

    bash
    mv config/local.json config/local.json.bak
    git pull
    git diff --no-index config/local.json.bak config/local.json

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Run git status before each pull, and commit often in small steps instead of keeping a lot of uncommitted work.
  • Put generated or machine-specific files in .gitignore (.env, caches, local IDE configuration).
  • Enable rebase.autoStash so Git automatically stashes and reapplies your changes during a git pull --rebase.

Frequently asked questions

Did I lose my changes?

No. Git stopped before touching anything (Aborting): your files are exactly as they were before the command.

How do I force the pull and overwrite my local files?

With git fetch origin then git reset --hard origin/main. This command erases every uncommitted change and every unpushed local commit: run git stash or create a backup branch first.

Where are my changes after git stash?

In the stash stack. git stash list shows them, git stash show -p shows their content and git stash pop reapplies them.

Useful tools for this error

More Git & GitHub errors

All Git & GitHub errors →