gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.
gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.
Check the file you're ignoring Take a good look at your structure, and make sure you're trying to ignore the file that isn't already committed to your repository. If it is, remove the file from the repository and try again. This should fix the Gitignore not working issue.
I'm guessing this folder has been checked into git before?
Run git rm -r --cached <folder>
and check again.
For me, the accepted answer was part of the solution, not the entire solution. Maybe, the other steps that I'm about to post were obvious, but I missed them first. Here's the steps I took to ensure my .gitignore
file ignored the folder I wanted it to ignore:
git rm -r --cached .
(which removes everything from the git index in order to refresh your git repository)git add .
(to add everything back to the repo)git commit -m ".gitignore Fixed"
You can find the link to the article from where I found the solution here.
I was having this issue and I realized git was actually ignoring the files/folders correctly, but my code editor (Visual Studio Code) was just buggy and not "greying them out" properly in the UI sidebar. I restarted VSCode and they were greyed out as expected.
As an addition to the accepted answer
git rm -r --cached /foo/bar/
git status
When i do that, the terminal shows a bunch of rm
for files in that directory. So to prevent another commit that might unnecessarily affect remote, I i did:
git reset HEAD *
git status
After that, it said nothing to commit and when i modify files inside /foo/bar/
and do a git status
i still get nothing to commit
.
I had done echo node_modules >> .gitignore
and it didn't work.
the windows terminal from saves the file in UCS-2 LE BOM
and git doesn't seem to accept that.
I opened the file with Notepad
and saved 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With