Search code examples
gitgitignore

.gitignore not matching subdirectories


I have directory tree like this:

__pycache__
systems
    __pycache__
    ...
components
    __pycache__
    ...
...

I tried the following .gitignores to ignore all __pycache__ directories. However, they are not working - only the first one is ignored.

**/__pycache__/ and __pycache__/

How do I ignore all of them?


Solution

  • Because I am on Windows, do I have to use a backslash instead

    No, you do not need to use a backslash. This is enough to ignore all _pycache__/ folders:

    __pycache__/
    

    Make sure your .gitignore is at the root folder of your repository.

    Check that this has an empty output:
    git check-ignore -v -- components/_pycache__/aFile

    To be sure, try this and then check again:
    git rm --cached -r components/_pycache__/