Git101: When You Can And When You Can Not Switch Branches — When Just Modifying Files
1 min readSep 11, 2021
The aim of this page📝is to show when can you switch branches with modified files without getting
Your local changes to the following files would be overwritten by checkout
Maybe not a best practice, but sometimes I just need to test a freshly modified script across branches (I use feature branch for each markdown document to be dispatched to Zendesk) — this is where the need to understand these particular mechanics comes from.
1. notes
- Create a branch1
- Modify file
- Checkout branch2
- Succeeds
- Checkout branch1
- Stage/commit initial changes to branch1
- Modify file again
- Do not stage/commit yet
- Checkout branch2
- Fails
error: Your local changes to the following files would be overwritten by checkout:
<file>
Please commit your changes or stash them before you switch branches.
Aborting