Reputation: 157
Let's say we have the following scenario: - I created a new branch and checked it out (git checkout -b ). - On the new branch I changed a file - If I want to switch back to master, git throws the following warning: "error: Your local changes to the following files would be overwritten by checkout..."
I think this is how git should behave. I have other colleagues who work on the same project but when they do the same as above, the warning does not appear and git simply switches the branch. It even seems to merge the files automatically and git status shows the same on both branches. Why do I get the warning and they don't? Is this a setting thing?
Thanks in advance.
Upvotes: 2
Views: 584
Reputation: 39981
If you create a branch and edit a file on that branch and, without committing it, checkout the master branch before any other changes happens on master you will not get that warning.
Only if any of the files differ between the two branches git will issue an error.
Upvotes: 1
Reputation: 467221
You should only get that error if the state of the file in HEAD
(your current commit) is different from its state in the branch you're trying to check out, since then git can't easily be sure that it can carry your local changes over to the new branch.
Your first example is slightly confusing, though:
I created a new branch and checked it out (git checkout -b ). - On the new branch I changed a file - If I want to switch back to master, git throws the following warning: "error: Your local changes to the following files would be overwritten by checkout..."
I assume that since you got that warning, you were either creating the new branch based on a something other than master
, or you'd created a commit that introduced changes to that file before making further local modifications and trying to checkout master
again.
Upvotes: 1