How to make git forget a previously tracked file

Have you run into a situation where you accidentally checked in a file, and now you add it to .gitignore, but git just won’t forget about it?

Here is how to fix it,

git rm -r --cached
git add .
git commit -am "removing ignored files"