Can you create a .gitignore
file in a directory that only applies to files (and directories) within that directory?
Asked
Active
Viewed 6.9k times
164
3 Answers
242
Yes, you can. Try it, it works fine. Put a .gitignore
in the root of your repo, and put another .gitignore
with additional things to ignore in a subdirectory.

Mike Morearty
- 9,953
- 5
- 31
- 35
-
8Does the .gitignore in the subdirectory replace the root .gitignore? Or does it add to it? – dsula Oct 20 '21 at 13:54
-
2@dsula the .gitignore in the subdirectory adds to the root .gitignore (does not just replace it). – Mike Morearty Mar 12 '22 at 00:13
14
Similar question was: Are multiple `.gitignore`s frowned on? (Jul 2010)
Or if you can have different version of a .gitignore
file per branch: Using github to host public git repositories whilst ensuring that sensitive data files remain untracked (Feb 2010)
Further perhaps related: How do I tell git to always select my local version for conflicted merges on a specific file?

Community
- 1
- 1

Tats_innit
- 33,991
- 10
- 71
- 77
3
You can just specify files to ignore in a format such as
Xyz/*.abc
in the .gitignore in the root directory, potentially removing the need for separate ignore files.

learnvst
- 15,455
- 16
- 74
- 121