How to Remove node_modules from Repo (after adding .gitignore file)

Learn how to remove node_modules after they have been added to a remote repository.

How do you delete node_modules from your remote git repository if you added your .gitignore file after you already pushed your node_modules?

You might expect that your node_modules directory will automatically get deleted on your next push since you put it in your .gitignore file, right?

It doesn’t.

You have to remove the node_modules folder from the git repository first (right after creating your .gitignore file):

git rm -r --cached node_modules

Now you can commit your repository without node_modules:

git commit -m "Removed node_modules"

And push your changes:

git push origin master

Now node_modules will get deleted from your remote repository.

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊


Share & Discuss on