'.gitignore arbitrary sub git repositories

I'm trying to find a catch-all solution for a .gitignore to exclude any directories containing another git repository. The motivation is to be able to locally organize git-repositories hierarchically without git status telling you there is something untracked.

In my mind it would look like;

# exclude sub git directories
**/.git/..

and as I understand the disassembled parts

  • ** : anywhere in the repository
  • / : any directory
  • .git/ : with a .git/ directory
  • .. : exclude the directory containing the .git/

An example would be to exclude bar/-directory in the foo/-repository from file-tree: https://i.stack.imgur.com/kXgjR.png

However, git does not seem to regard foo/bar/.git/.. equivalent to foo/bar/, or foo/bar/./ for that matter.

Suggestions?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source