Triggering the Real Conflict
# edit cookies.md's Variations line, uncommitted
git checkout spicy-experiments
error: Your local changes to the following files would be overwritten by checkout:
cookies.md
Please commit your changes or stash them before you switch branches.
Aborting
This is real protection, not a bug: spicy-experiments' own committed version of cookies.md differs from your uncommitted edit, and checking out would silently discard one of them. Git refuses rather than guess.
Escaping With git stash
git stash
git checkout spicy-experiments
git stash pop
git stash genuinely removes the uncommitted edit and saves it separately, leaving the working directory clean enough to switch. git stash pop reapplies it — here, cleanly, since the edited line does not overlap with anything spicy-experiments changed independently.
Committing It Where It Belongs
git add cookies.md
git commit -m "Add chili flakes note to variations"
The edit now genuinely lives on the branch it was meant for all along.
While spicy-experiments sat there with its one ghost pepper commit, real work continued on master too — a serving note was added to the cookie recipe. cookies.md now genuinely differs between the two branches, which is completely normal — but it sets up today's real interruption.
You start editing cookies.md on master to add a note about chili flakes, then realize: this note belongs on spicy-experiments, not here. You try to switch. Git says no — and for good reason. This lesson makes that real error message make sense, and practices the standard way out of it.
Checkout conflict
Git's real refusal to switch branches when doing so would silently overwrite uncommitted changes that genuinely differ from the target branch's own version of the same file. Confirmed directly in this lab: the exact same edit on a file that does NOT differ between branches would not have triggered this.
git stash
Temporarily removes uncommitted changes from the working directory and saves them on a real internal stack, leaving a clean working tree. git stash pop reapplies the most recent stash and removes it from that stack — confirmed directly in this lab applying cleanly onto a different branch than the one it was stashed from.
Takeaways
- Git refuses a checkout only when your uncommitted edit genuinely conflicts with the target branch's own version of the same file
- The real error message names the exact file at risk and tells you exactly what to do — commit or stash
- git stash removes uncommitted changes and saves them separately, leaving a clean working tree that can switch freely
- git stash pop reapplies the most recent stash and can apply cleanly across a branch switch when the change does not overlap with what the other branch did
- Committing the edit in place is an equally valid escape route when the change genuinely belongs on the current branch