Git ignore not removing files from my Repo

102 Views Asked by At

Already tried doing git rm --cached dir/file and it did not work. It only works with the VSCode interface(the source control extension).

I'll add a file to .gitignore

git add . 
git commit -m "trying to make .gitignore work"
git push

And no success...

I already visited all the other duplicates of this one on Stackoverflow.

I am using WSL (Windows Subsystem for Linux) on VScode.

The file remains on my git repo even if its marked on gitignore...

The file name on VScode interface shows up a little gray indicating that .gitignore worked...

1

There are 1 best solutions below

3
On

git rm --cached dir/file should work, provided you do a commit and a push.

Note that the --cached option means the file remains on your disk.
And that it is removed (and ignored) only for this new commits (and the future ones), not the past commits.

Also check if, locally, the .gitignore rule applies with:

git check-ignore -v -- dir/file

No output means: it is not ignored.