Remove node_modules from a git repo
Stop tracking a committed node_modules folder and ignore it going forward.
If node_modules ended up committed, adding it to .gitignore alone won't help — git keeps tracking files it already knows about. You need to drop it from the index too.
Make sure a .gitignore exists at the repo root, then add the ignore rule:
**/node_modulesDrop node_modules from the index without deleting it from disk:
git rm -r --cached node_modulesCommit the removal alongside the updated .gitignore:
git add .gitignore
git commit -m "Stop tracking node_modules"
git push origin mainAnyone who pulls will see node_modules deleted from their checkout — they'll need to run npm install (or equivalent) to repopulate it.
Liked this? Get the next one in your inbox.
One email every other Tuesday. Engineering, product, and what I'm shipping. Unsubscribe anytime.