.gitignore is not ignored by node_modules / folder

I'm trying to get git to ignore my files in node_modules / and it doesn't seem to accept this change.

Here is the content of my file .gitignore

:

node_modules/

      

and here is my project structure:

enter image description here

I would expect the node_modules folder and all files / folders in it to be ignored by git, but instead I get a whole ton of changes listed as pending and even when I make the git state at the root node_modules / appears as pending. Is there some kind of nomenclature on Windows that makes git weird?

+4


source to share


2 answers


Just add /

before node_modules/

should be like

/node_modules/

# ^ forward slash before the folder name signifies root dir

      



If you only want to exclude certain files in the node_modules folder, you can also do something like /node_modules/*.json

to exclude all files inside the root node_modules folder with the extension .json

.

+4


source


try

node_modules/*

      

if you want to add folder but not content add



.gitkeep

      

into a folder, and this is .gitignore

!node_modules/.gitkeep 

      

-2


source







All Articles