I added the following line to .gitignore:
sites/default/settings.php
but when I type git status it shows the file
One thing that I think has been missed in the excellent answers here is the existence if another *.gitignore* or multiple of them.
In a case, I had cloned a repo and could not figure out why a "ignored" file was being added again when running git add. It worked out that there was another .gitignore in a subfolder and that was overriding the one in the root folder.
/.gitignore
/some-folder/.gitignore
/some-folder/this-file-keeps-getting-staged
The
root /.gitignore
was ignoring this-file-keeps-getting-staged
The
/some-folder/.gitignore
did not have a specification to ignore "this-file-keeps-getting-staged" file.
And hence the issue.
One of the things is to simply search for multiple .gitignore files in the hierarchy. And figure out the rules as they apply.