I can think of at least two situations where you would want to have multiple .gitignore files in different (sub)directories.
-
Different directories have different types of file to ignore. For example the
.gitignorein the top directory of your project ignores generated programs, whileDocumentation/.gitignoreignores generated documentation. -
Ignore given files only in given (sub)directory (you can use
/sub/fooin.gitignore, though).
Please remember that patterns in .gitignore file apply recursively to the (sub)directory the file is in and all its subdirectories, unless pattern contains “https://stackoverflow.com/” (so e.g. pattern name applies to any file named name in given directory and all its subdirectories, while /name applies to file with this name only in given directory).