Pushed node_modules but cant figure out how to remove

Viewed 687

I push the node modules up to GitHub, then realized I did not have a .gitignore.

I added the gitignore but it did not fix the problem.
I found answers on here that said to remove it from the cached with git rm -r --cached node_modules, but this wont work because it says it cannot find that file, and I can still see it in my repo as well.

My file structure is the repo, then a dev folder with node_modules inside it, along with all the other code I have written.
The .gitignore is outside of the dev folder, next to the README file.

Do I need to give the .gitignore a path to find the modules like a ./node_modules or something?

3 Answers

the gitignore is outside of the dev folder next to the readme file

Then, it should include:

dev/node_modules/

That would ignore the dev/node_modules folder, and its content.

Check that (after a git rm --cached dev/node_modules done from the root folder of your repo) with:

git check-ignore -v -- dev/node_modules/afile

(test it on one existing file inside that dev/node_modules/ folder)

If you've added just node_modules in the .gitignore file, then it ignores all the node_modules directories within the repo. So you are just fine with .gitignore configuration.

The issue is that you should use the correct path when removing the cached copy of the node_modules. It should be as follows from the root of your repository.

git rm -r --cached ./dev/node_modules

Add this in .gitignore

dev/node_modules/

Now reset cache.

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
Related