My .gitignore
file seems to be being ignored by Git - could the .gitignore
file be corrupt? Which file format, locale or culture does Git expect?
Another possible reason – a few instances of Git clients running at the same time. For example, "git shell" + "GitHub Desktop", etc.
This happened to me. I was using "GitHub Desktop" as the main client, and it was ignoring some new .gitignore settings: commit after commit:
Reason: the Visual Studio Code editor was running in the background with the same opened repository. Visual Studio Code has built-in Git control, and this makes for some conflicts.
Solution: double-check multiple, hidden Git clients and use only one Git client at a time, especially while clearing the Git cache.
Without adding another commit to your project, one line will be enough to make .gitignore
work as it is supposed to:
git rm -r --cached debug.log nbproject
This will remove them from the repository, but still keep them physically. In plain English, it deletes any history of changes related to them, and also will not track their change in any future commit. You may find a better explanation here.
Another cause of this issue is blank spaces or tabs before the statement:
Example:
# Be aware of the following:
notWorkingIgnore.*
workingIgnore.*
And as pointed out by the comment below a trailing space can be an issue as well:
# Be aware of the following:
notWorkingIgnore.* #<-Space
workingIgnore.*#<-Nospace
I had this same problem. I believe the issue was a CR vs. CR+LF discrepancy. I stashed things in my .gitignore using CMD (on Windows 7) and the following command:
Bad:
echo "file_to_be_ignored.py" >> .gitignore<br>
echo "*~" >> .gitignore
Etc.
The issue was that this command does not place the correct end-of-line marker for Git to recognize the newlines (either CR or CR+LF when Git expects the other). I solved the problem by manually replacing each newline in Vim (Vim to the rescue!) and it worked perfectly.
Try editing your .gitignore in Notepad++ or Vim (ideally). Even if the file looks like it's formatted correctly, try replacing the newlines. It sounds weird, I know, but it worked for me. :D
OK, so in my case the accepted solution did not work, and what worked is described here:
Is Visual Studio 2013 ignoring your .gitignore file?
In short:
ms-persist.xml
Mine wasn't working because I've literaly created a text document called .gitignore
Instead, create a text document, open it in Notepad++ then save as .gitignore
Make sure to pick All types (*.*) from the dropdown when you save it.
Or in gitbash, simply use touch .gitignore