Local Changes Would Be Overwritten
Error message
error: Your local changes to the following files would be overwritten by checkout
Quick summary
Switching branches would overwrite your uncommitted changes, so Git stopped to protect your work.
Why this happens
You have modified files that conflict with the target branch's version
You tried to switch branches with a dirty working tree
A pull or checkout would overwrite local modifications
Minimal example
git checkout main # error: local changes would be overwrittengit stash
git checkout main # succeeds
git stash pop # restore changesStash saves your changes temporarily, allowing the branch switch. Pop restores them afterward.
How to diagnose
Run git status to see which files are modified
Decide if the changes should be kept, committed, or discarded
Check if the changes are staged or unstaged
How to fix
Commit the changes: git add . && git commit -m "Save work"
Stash them: git stash, then checkout, then git stash pop later
Discard them: git checkout -- <file> (if you do not need the changes)
Force checkout: git checkout -f <branch> (destroys local changes)
How to prevent
Commit or stash before switching branches
Run git status regularly to stay aware of uncommitted changes