Most of the time when I try to checkout another existing branch, Git doesn’t allow me if I have some uncommitted changes on the current branch. So I’ll have to commit or stash those changes first.
However, occasionally Git does allow me to checkout another branch without committing or stashing those changes, and it will carry those changes to the branch I checkout.
What is the rule here? Does it matter whether the changes are staged or unstaged? Carrying the changes to another branch doesn’t make any sense to me, why does git allow it sometimes? That is, is it helpful in some situations?