4

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

Here is the content of my .gitignore file:

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 am getting a whole ton of changes listed as pending, and even when I do a git status in the root, node_modules/ is listed as pending. Is there some nomenclature about Windows that is making git act strangely?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
ddeamaral
  • 1,403
  • 2
  • 28
  • 43
  • Possible duplicate of [How do I hide certain files from the sidebar in Visual Studio Code?](https://stackoverflow.com/questions/30140112/how-do-i-hide-certain-files-from-the-sidebar-in-visual-studio-code) – alexmac Aug 04 '17 at 20:48
  • Please don't include screenshots of text in your question. Include the relevant code and configuration as *text*. – user229044 Aug 05 '17 at 04:29

2 Answers2

7

Just add / before node_modules/, should be like

/node_modules/

# ^ forward slash before the folder name signifies root dir

If you are looking to exclude specific files only in node_modules folder, you can also do something like /node_modules/*.json will exclude all files inside root node_modules folder with .json extension.

Sagar Devkota
  • 1,295
  • 3
  • 12
  • 25
-2

try

node_modules/*

if you want to add the folder but not the content add a

.gitkeep

file to the folder and this to .gitignore

!node_modules/.gitkeep 
Auskennfuchs
  • 1,577
  • 9
  • 18