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"
Then reinstalled the npm dependencies by using npm install
After this I expect to have the directory node_modules
to be finally ignored.
Instead if I type git status
I get
Untracked files:
(use "git add <file>..." to include in what will be committed)
node_modules/
Why?
Under this question there are many possible fixes for a .gitignore
file not properly working.
In this case the problem is (was) that the .gitignore
file's encoding was UNICODE instead of ASCII
Try the following:
Remove node_modules from .gitignore and save it
Delete node_modules (or move it somewhere outside from the project directory)
Commit the changes (there will be a tons of deletion from node_modules) This step will remove the files from source control.
Add node_modules to .gitignore again
Commit gitignore
Re-run npm install or restore the node_modules directory.
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