When you do a git checkout some_branch
, and your working directory is not clean, then Git will check if the checkout will result in any conflicts, and if so it will abort with:
$ git checkout some_branch
error: Your local changes to the following files would be overwritten by checkout:
some_file
Please, commit your changes or stash them before you can switch branches.
Aborting
However, if the checkout will not result in any conflicts, then Git will switch to that new branch and carry over all uncommitted changes (and listing them, polite as Git is).
$ git checkout some_branch
M some_file
M some_other_file
Switched to branch 'some_branch'
So far so good ...
Now, not all Git users uses cmd line. If you use an IDE (like e.g. Eclipse) and do a checkout of some_branch
with a dirty working directory which will not result in any conflicts, then you will not be nicely notified that the changes you were working on in previous_branch
are still present in your working directory after changing to some_branch
.
I.e. when you compile your code your uncommitted changes from previous_branch
are still present in your working directory on some_branch
.
Question #1:
Is it possible to force Git to abort a checkout if working directory is not clean (no matter if there are any conflicts or not)?
I would prefer a setting in global Git config.
Question #2:
If this is not possible to setup, is it then a valid request for a new config option in Git?
As I see it Git is very strong in context switching (i.e. working on multiple issues on multiple branches), and I could see a use for a setting which setup a strict check for if working directory is not clean (disregarding the check for conflicts).
This would mean that your changes created while on branch #1 will not be carried over when changing to branch #2, i.e. you will work strictly context based always.
Any views or opinions on this?