Can git be made to ignore nested .gitignore files when computing ignores?

I wanted to track some files ignored by a bunch of repos into a single repo.

Here’s an example layout:

.
+-- .git
+-- .idea
|-- .gitignore
|-- proj1
|   +-- .git
|   |-- .gitignore
|   |-- foo
|   |   |-- foo.iml
|   |-- bar.c
|   |-- proj1.iml
|-- proj2
    +-- .git
    |-- .gitignore
    +-- bar
    |-- foo.c
    |-- proj2.iml

I want:

  • the root-level repo to include all *.iml files, while each sub-repo individually ignores them
  • all the repos to be independent (the projects don’t depend on the root, and can be manipulated separately)
  • this folder structure to be maintained

Any solution?

  • Setting up GIT for Symfony2 project: why add web/bundles folder to gitignore
  • How do I track only specific files using .gitignore?
  • Stop tracking a file in git - without having it deleted either locally or on pull
  • exclude only js files from gitignore
  • Ignore already tracked files? (using Tower for Mac to work with a git repository)
  • gitignore all except file in sub-sub folder
  • Git still adds and tracks folders marked in .gitignore
  • How can I git pull ignored files?
  • One Solution collect form web for “Can git be made to ignore nested .gitignore files when computing ignores?”

    The title of the question and the detailed description seem to ask slightly different questions…

    With regards to the title of the question: to exclude nested .gitignore files, but not the root .gitignore itself, add the following line to your root .gitignore file:

    */**/.gitignore
    

    (this will only ignore those .gitignore files that are nested at least one folder level deep)

    Alternatively, if you only want to ignore .gitignore files in direct child folders, but still want to include all .gitignore files in indirect (i.e., 2nd level, 3rd level,…) sub-folders use:

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