ignore gitignore files in subdirectories

This is the content of my “root” .gitignore

# exclude everything ...
*
# ...except
!/.gitignore
!*/
!/modules/wp-azth/**

the problem is that, under modules folder, i’ve a lot of third-party modules with a .gitignore file inside.

Using rules above, all third-party modules folders are ignored but their .gitignore files are not ( and i don’t need it of course )

is there a way to ignore .gitignore files inside ignored subfolders? maybe .git/config can be used for this?

( i think it’s a bad behaviour of git that considers them even if they are ignored )

UPDATE: It seems a lack of git, it allows ignored folder to “arbitrary” un-ignore itself having !.gitignore rule inside a gitignore file placed ( by anyone ) inside an ignored subdirectory.
Ignored folders normally could contains files that are dynamic , temporary or 3rd party ( cache, temp, plugins etc ) … so git allows to create unwanted behaviours just using a simple !.gitignore as rule inside subdirectory.

git gui screenshot

  • How do I clone a subdirectory only of a Git repository?
  • Checkout subfolder in git
  • How to make a separate Eclipse project out of a subfolder under Git source-control
  • Git Ignore everything in a directory except subfolders
  • Git. Store several projects under the same repository
  • Retrieve pod from a folder inside a repo
  • Completely independent Git project within another project using only gitignore
  • How do I clone a subdirectory only of a Git repository?
  • 2 Solutions collect form web for “ignore gitignore files in subdirectories”

    *.gitignore will work, however git will still track .gitignore files it was already tracking


    The only different between the two commands being ran is that I add *.gitignore (via the command you see in the middle) to my root level .gitignore file.

    Showing *.gitignore works


    An optional prefix “!” which negates the pattern; any matching file
    excluded by a previous pattern will become included again.

    from https://git-scm.com/docs/gitignore

    Meaning it might be possible that a middle level .gitignore file(s) has !*.gitignore in it, which might be messing up the higher level declaration.

    The problem is .gitignore files within the /modules directory:

    git check-ignore -v -n /modules/TC-JSON-API/storage/app/.gitignore
    returns: /modules/TC-JSON-API/storage/app/.gitignore:2:!.gitignore /modules/TC-JSON-API/storage/app/.gitignore

    The solution then was just adding /modules/* to my .gitignore:

    # exclude everything ...
    *
    # ...except
    !/.gitignore
    !*/
    !/modules/wp-azth/**
    

    became

    # exclude everything ...
    *
    modules/*
    # ...except
    !/.gitignore
    !*/
    !/modules/wp-azth/**
    

    i didn’t understand why git needs this kind of “specification” …without that rule only .gitignore files of ignored folder are processed/listed in commit. However now it works.

    Git Baby is a git and github fan, let's start git clone.