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 located just above the .git directory. Inside the .git directory, the file has no effect.
This makes sense, because usually you want to put this file under version control to share the list of ignored files with all the developers of the project. And only files inside the working tree, outside .git are under version control, the .git directory is intended for internal git storage.
(If you want to ignore templates only locally without adding version control, you can do this by specifying templates in .git/info/exclude .)
[...], and also tried to add a comment line to the first line, since apparently git is not reading the first line of this file
For writing, it also reads the first line, there is nothing special about the first line in .gitignore .
source share