Why doesn't Git ignore my specified file?
Make sure that your .gitignore
is in the root of the working directory, and in that directory run git status
and copy the path to the file from the status output and paste it into the .gitignore
.
If that doesn’t work, then it’s likely that your file is already tracked by Git. You can confirm this through the output of git status
. If the file is not listed in the “Untracked files” section, then it is already tracked by Git and it will ignore the rule from the .gitignore
file.
The reason to ignore files in Git is so that they won't be added to the repository. If you previously added a file you want to be ignored, then it will be tracked by Git and the ignore rules matching it will be skipped. Git does this since the file is already part of the repository.
In order to actually ignore the file, you have to untrack it and remove it from the repository. You can do that by using git rm --cached sites/default/settings.php
. This removes the file from the repository without physically deleting the file (that’s what the --cached
does). After committing that change, the file will be removed from the repository, and ignoring it should work properly.
I run into this, it's an old question, but I want that file to be tracked but to not track it on certain working copies, to do that you can run
git update-index --assume-unchanged sites/default/settings.php
.gitignore will only ignore files that you haven't already added to your repository.
If you did a git add .
, and the file got added to the index, .gitignore won't help you. You'll need to do git rm sites/default/settings.php
to remove it, and then it will be ignored.