2

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?

sclarke81
  • 1,739
  • 1
  • 18
  • 23

1 Answers1

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:

Note: there is no pre-checkout hook, even though one was proposed in 2009.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    It'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