Git: Your local changes would be overwritten by checkout
A plain-words explanation of this Git message: what it means, the usual causes, and the steps that fix it.
The messageerror: Your local changes to the following files would be overwritten by checkout:
Make the error yourself
Run with git version 2.56.0.windows.4. This is the smallest example we could find that shows it.
Setup used before these commands (a practice folder with no data)
export GIT_AUTHOR_NAME=Asha GIT_AUTHOR_EMAIL=a@example.com GIT_COMMITTER_NAME=Asha GIT_COMMITTER_EMAIL=a@example.com
git init -q -b main
echo "version 1" > f.txt
git add f.txt
git commit -qm base
git switch -q -c other
echo "version 2" > f.txt
git commit -qam other
git switch -q main
echo "unsaved work" > f.txtCommands
git checkout otherGit prints (the real message)
error: Your local changes to the following files would be overwritten by checkout:
f.txt
Please commit your changes or stash them before you switch branches.
AbortingWhy it happens
You have edited a file and not committed the change. The branch you want to switch to has a different version of the same file. If Git switched, it would replace your edit and you would lose it, so Git refuses and names the files. The same message appears for git pull and git merge ("would be overwritten by merge"). Git protects you here, so do not try to bypass it.
How to fix it
- Commit your work:
git add .andgit commit -m "work in progress", then switch. - Or put it aside with
git stash, switch, and bring it back later withgit stash pop. If the same lines were changed in the other branch, the stash pop can conflict and you resolve it like a merge. - If you do not need the edits, throw them away with
git restore <file>. This cannot be undone.
The corrected version
Commands
git stash
git checkout otherGit prints (the corrected version)
Saved working directory and index state WIP on main: cae1333 base
Switched to branch 'other'How to avoid it
Commit small changes often so that switching branches is easy, and run git status before you switch.
Questions
Where does the stash go?
Into a list inside the repository. git stash list shows it, and git stash pop applies the newest entry and removes it from the list.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.