Search code examples
gitgitignore

ignore directory which has .git subdirectory?


I'd like to ignore directories if it has it's own .git directory.

project-root
  - sub-project1 (with `.git`)
  - sub-project2 (with `.git`)
  - other files

How can I tell(.gitignore) to ignore all the directories with its own .git such as sub-project1/2 ?


Solution

  • You would need a script which would:

    • find an .git subfolder
    • take their parent folder (dirname)
    • add it to .gitignore (if not already present)
    • remove it from the index (in case it would already recorded by the parent repo as a gitlink entry)