user3808318
user3808318

Reputation: 1157

Multiple .gitignore in subfolders

Is it possible to have a .gitignore file in a subfolder, so that I may be better able to control what I need to be ignored and not affect a larger, "base" gitignore?

For example, there is the root .gitignore, but instead of lets say writing /path/to/folder in that file, in my folder to have another .gitignore that will only apply for that folder and it's children?

Upvotes: 43

Views: 18913

Answers (1)

user3808318
user3808318

Reputation: 1157

Answer is: Yes, it is possible to have a .gitignore file in a subfolder.

Documentation:

When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):

  • Patterns read from the command line for those commands that support them.

  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

  • [...]

Thanks alfunx

Upvotes: 51

Related Questions