Complete copy&paste recipe, just adding the commands in the comments (for the copy-paste solution), after testing them:
git filter-branch --tree-filter 'rm -rf node_modules' --prune-empty HEAD
echo node_modules/ >> .gitignore
git add .gitignore
git commit -m 'Removing node_modules from git history'
git gc
git push origin master --force
After this, you can remove the line "node_modules/" from .gitignore