Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 878
user3808318 Avatar asked Nov 08 '18 12:11

user3808318


1 Answers

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

like image 200
user3808318 Avatar answered Nov 16 '22 13:11

user3808318