when switching branches, I noticed that sometimes my local changes to the current branch is automatically kept in the branch switched to, it will show a message like this :
M <source file name>
But sometimes, it tells me I need to stash my local changes first.
Why is the behavior not consistent? and Is there a way to force it automatically move the local changes to the new branch because I constantly modify the wrong branch.
Thanks.
Git will re-apply the current changes in the worktree to the new branch if it can do so without any problems, i.e. the same file was not modified between the current branch (
HEAD) and the branch being switched to.