问题 I started a project using npm, added a few dependencies and then initialized the repository usign git init . I wanted the directory node_modules to be ignored by git, so I added it to the .gitignore file like so. .gitignore node_modules/ Of course because node_modules was added before git init , it is still recognized as a directory to track. So I deleted it, used the following commands (as suggesed for similar problems) git rm -r --cached . git add . git commit -m ".gitignore should now work