ProjectStack
git

error: please commit or stash your changes before you switch branches

You're trying to switch branches but have uncommitted changes to files that differ between the two branches. Git won't let you switch because it would lose or overwrite your local edits.

Common causes

  • You edited files that exist differently on the target branch
  • You forgot to commit work-in-progress before switching context
  • A save or auto-format tool modified tracked files
  • You modified a file that was deleted or renamed in the target branch

How to fix it

  1. Commit the changes: git add . && git commit -m 'WIP'
  2. Or stash them: git stash, switch branches, then git stash pop when you return
  3. Discard the changes if they don't matter: git checkout -- <file> or git restore <file>
  4. Use git status to review exactly which files are affected before deciding

Example

error: Your local changes to the following files would be overwritten by checkout: src/config.js Please commit your changes or stash them before you switch branches.

Running git checkout <other-branch> with uncommitted changes

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.