Šime Vidas
Šime Vidas

Reputation: 185873

How to gitignore files in a directory but not files in its sub-directories?

Folder structure

I would like to gitignore the files directly inside the "bar" directory (file1 and file2), but not the files inside any sub-directory of "bar" (in this example, file3 and file4 should not be ignored).

I checked the docs. Seems to be incomplete.

Upvotes: 0

Views: 82

Answers (1)

jcm
jcm

Reputation: 1789

You can ignore the files in the bar directory

# foo/bar/.gitignore
*.js

and then whitelist in the baz directory

# foo/bar/baz/.gitignore
!*

From the docs on kernel.org:

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.

Upvotes: 1

Related Questions