gitignore not ignoring file
You can only ignore unversioned files but that file is already known to git.
If you want git to track that file, there is no need to tell git to ignore it.
If you don't want git to track that file use git rm
and your ignore rule will start working.
Caution: git rm
will remove the file. Use git rm --cached
to remove from the repo but not from the disk.
I had same problem.
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore working now"
To undo git rm --cached filename, use git add filename.
If you have done something like echo node_modules >> .gitignore
, it won't work.
The windows terminal saves the file in UCS-2 LE BOM
and git doesn't seem to accept that.
You can open the file with Notepad
and save it with UTF-8
encoding
It Works now.
I think they need to fix this since echo "filetoignore" >> .gitignore
actually seems a handy thing to do