Even after adding the .gitignore
file to the root of the .git
repository, I cannot make git ignore the node_modules
directory.
The files have not been added for Git to track.
I have gone through earlier stack overflow questions, and also tried adding a comment line to the first line, since apparently Git doesn't read the first line of that file, and it still doesn't work. I have tried to use the following command also, with no avail:
git rm --cached -r .
Could anyone help me out? The content of .gitignore
:
#first line node_modules/
gitignore list does not work to ignore files that are already committed into the Git repository. This means that if you: Make a commit to your Git repository, and then; Set up your .
Gotcha #2 - node_modules already committedIf you've already committed node_modules , you'll need to first remove the directory from git index. Otherwise, adding it to . gitignore won't make any difference.
Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.
There are several locations where Git looks for ignore files. Besides looking in the root folder of a Git project, Git also checks if there is a . gitignore in every subdirectory. This way you can ignore files on a finer grained level if different folders need different rules.
Even after adding the .gitignore file to the root of the .git repository, I cannot make git ignore the node_modules directory.
The .gitignore
file should be placed in the root of the working tree (also known as the root of your project), which is just above the .git
directory. Inside the .git
directory the file has no effect.
This makes sense, because normally you want to put this file under version control, to share the list of ignored files with all developers on the project. And only the files inside the working tree, outside .git
are under version control, the .git
directory is for Git's internal storage.
(If you wanted to ignore patterns only locally, without adding to version control, you could do so by defining patterns in .git/info/exclude
.)
[...] and also tried adding a comment line to the first line, since apparently Git doesn't read the first line of that file
For the record, it does read the first line too, there's nothing special about the first line in .gitignore
.
I don't know if this will help anyone but I created my .gitignore file in PS with echo "" > .gitignore and thus the encoding was set to UTF-16LE and not UTF-8. This caused problems with .gitignore working properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With