Reputation: 60748
This surprises me and I can't think of how it can be possible.
git checkout -b newbranch
.Foo.java
.git checkout master
(which was the original branch I was on) gives error:
error: Your local changes to the following files would be overwritten by checkout:
Foo.java Please, commit your changes or stash them before you can switch branches.
git stash
git checkout master
And it auto-merges successfully. Why did it need to auto-merge at all? Why did it need to block my git checkout
going away from master
but not back to master
? I'm trying to understand the logic for when git
makes these complaints.
Upvotes: 1
Views: 133
Reputation: 17848
When you used git checkout -b
it didn't actually go away, it stayed on the same commit. That's why it allowed you to checkout keeping all the local changes. Going "back" to master changes the commit (and actually modifies the working tree), that's why it would override your changes.
Upvotes: 3