How to remove node_modules and prevent it from being pushed again after an accidental push
- Create a .gitignore file if it doesn't exist already
touch .gitignore
- Add the line
**/node_modules
to the .gitinore file to prevent tracking
The**/
a file or directory listed after the slash from being tracked no matter where it is in the repo
echo "**/node_modules" >> .gitignore
- Remove the currenty tracked node_modules
git rm -r --cached node_modules
- Add .gitignore
git add .gitignore
- Commit now that nodei_modules has been removed
git commit -m "removed node_modules and added it to the .gitignore"
- Push the changes
git push