As long as you don't commit it in subbranch, it is a private (untracked) file, not attached to any branch.
So when you switch back, that file is ignored and unchanged.
A git checkout -f master
would remove local changes (but not untracked files).
A git clean
would, but again, that mean you would loose the file. Start with a git clean -n
to see a preview.
A git stash
would save your untracked file (until you apply it again with a git stash pop
)