0

Currently git is not ignoring node_modules folder. I have tried below command:

git rm -r --cached node_modules

Output of above line:

fatal: pathspec 'node_modules' did not match any files

When I run git status I get the following output:

$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        configs/
        node_modules/
        package-lock.json
        package.json
        routes/
        server.js

nothing added to commit but untracked files present (use "git add" to track)

I don't want to include my node_modules/ folder the next time I run git add .. Currently it is adding all the files from node_modules/ folder.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • did you commit your gitgnore file? – karthick Jul 31 '18 at 16:30
  • loose the slash at the end of node_modules – karthick Jul 31 '18 at 16:32
  • Possible duplicate of [.gitignore is not working](https://stackoverflow.com/questions/11451535/gitignore-is-not-working) – phd Jul 31 '18 at 17:02
  • @karthick: I haven't committed anything till now. My current gitignore file has two lines only: node_modules package-lock.json – Hashmat Ali Jul 31 '18 at 17:12
  • @karthick, there is no need to commit the `.gitignore` for it to take effect. I'm not sure where this myth came from. (It is a _good idea_ to commit it so it becomes part of the repository. But not having it committed doesn't prevent it from working.) – ChrisGPT was on strike Jul 31 '18 at 18:54
  • @karthick, and if I'm understanding you correctly, the "slash at the end of node_modules" isn't in OP's `.gitignore`. It's the output from `git status`. – ChrisGPT was on strike Jul 31 '18 at 18:56
  • @Chris, that's good to know, I was always under the impression that gitignore needs to be committed inorder for it to work. – karthick Jul 31 '18 at 19:01
  • @HashmatAli, is your ignore file in the root of the directory and named `.gitignore` _exactly_ (note the leading `.`)? – ChrisGPT was on strike Jul 31 '18 at 19:05

1 Answers1

0

You need to add .gitignore file in same directory where are node_modules

and put this inside

# dependencies
/node_modules