I understand the behaviour (and usefulness) of being able to switch branches when you have uncommitted changes. However, in 99.9% of my workflow this is undesirable because it means I've forgotten to commit changes before switching to a different feature branch. Is there a setting somewhere that I can set to either not allow a switch with uncommitted changes or to at least give a warning?
Asked
Active
Viewed 456 times
1 Answers
2
There does not seem to be a config for that case (checkout with a dirty index).
That leaves you with writing a script git-co
(which can be called as git co
) which will:
- check for modified or untracked files (see "Checking for a dirty index or untracked files with Git")
- do the checkout only if the index is clean.
Note: there is no pre-checkout hook, even though one was proposed in 2009.
-
2It's a shame that this isn't possible, but thanks for the information. – sclarke81 May 17 '16 at 14:10
-
are there any news to this? I'd love to get this behaviour on my projects – Raphael_S Mar 10 '20 at 07:29
-
1@Raphael_S Check out (pun not intended) the new checkout command `git switch`: https://stackoverflow.com/questions/24384951/confused-by-git-checkout/57066202#57066202. For common files, it will block the switch. Fir for files which are modified, but not common with the destination branch, however... the switch might still occur. – VonC Mar 10 '20 at 07:37