GIT: remove folders that have already been commited and pushed

I have many a time added node_modules and the likes to my git repositories.

Tired of always googling it, I noted down this solution to cleaning up after.

  1. make .gitignore file (or update the one you have)

  2. add node_modules/ or what you want to get rid of line to the .gitignore file

  3. Run the following lines:

git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push