Conley Owens Conley Owens - 6 months ago 60
Git Question

Are multiple `.gitignore`s frowned on?

Unless a repo consisted of several independent projects, it seems it would be simplest to just have one

file at the root of the repo than various ones throughout. Is there a standard best practice on this or some analysis online of when one approach is better than the other?


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 .gitignore in the top directory of your project ignores generated programs, while Documentation/.gitignore ignores generated documentation.

  • Ignore given files only in given (sub)directory (you can use /sub/foo in .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 '/' (so e.g. pattern name applies to any file named name in given directory and all its subdirectories, while /name appliest to file with this name only in given directory).