Git not removing files when switching branch

I have seen this too. I usually just do a git reset --hard followed by a git clean -f -d and it usually does the trick.

It seems to definitely happen the most often when my IDE has a lock on one of the files in the branch i'm switching from.


First:

git reset --hard

Reset the repository to the state of the last commit.
Since git normally does not remove files it is not tracking those could still cause issues.

Then:

git clean -d --dry-run

See what files would get deleted. We don't want to loose valuable work. and if that is ok:

git clean -d