Fix "Your local changes would be overwritten by checkout"

You have uncommitted changes to a file that differs on the other branch, and switching would destroy them. Either commit them, or run git stash to put them aside, switch branches, and later run git stash pop to get them back.

Step by step

  1. Put your unfinished changes aside:

    $ git stash
  2. Switch branches safely:

    $ git switch main
  3. Later, come back and restore them:

    $ git switch newsletter
    $ git stash pop

The same error appears for git checkout, git switch, git merge and git pull. Git never silently throws away uncommitted work.

Try it in the interactive sandbox →Practice “Stash it” with a real repository and teammates, right in your browser.

Related guides