Michael Boutin

Remove node_modules from a git repo

bashMay 10, 2026

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:

.gitignore
**/node_modules

Drop node_modules from the index without deleting it from disk:

terminal
git rm -r --cached node_modules

Commit the removal alongside the updated .gitignore:

terminal
git add .gitignore
git commit -m "Stop tracking node_modules"
git push origin main

Anyone 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.

No spam. See the privacy policy.

  • bash

    Stop tracking a file that's already committed

    Adding a path to .gitignore does not untrack files git already knows about. Use git rm --cached to drop it from the index while keeping the local copy.

    May 6, 2026
  • bash

    Change a git remote's URL

    Point an existing remote at a new URL without removing and re-adding it.

    May 10, 2026
  • bash

    Delete local and remote git branches

    Delete branches one at a time, or sweep up local branches whose upstream has already been deleted.

    May 10, 2026