.gitignore for directories at a specific depth?
I have directories at
components/example/js/, and I don’t want these to be tracked by Git.
However, I have a directory
components/root/js2/plugins/js/, which I want to have tracked by Git.
I’ve looked up on this online and only found
**, which I believe does not solve my problem.
.gitconfig contains the line:
I’ve tried changing this to:
But this matches for
components/example/js/, but also
js folder below the second level of
components – I only want to ignore
js folders at the second level).
How can I achieve this goal?
2 Solutions collect form web for “.gitignore for directories at a specific depth?”
OK, how about this:
It will ignore all directories called
js except for ones specified after
!. In such scenario
git will ignore
components/root/js/ but won’t ignore
** won’t work because as it’s said in
A trailing “**” matches everything inside. For example, “abc/**”
matches all files inside directory “abc”, relative to the location of
the .gitignore file, with infinite depth.
You can put
.gitigore files in any directory which will be a more reliable solution if the directories are moved later.
I would create 2
One at the project root
One in the
/components/root/js2/plugins/.gitignorewhich overrides root
plugins directory will be moved later, e.g. to
.gitignore will be moved too.
If you configure everything in the root
.gitignore you must not forget to edit the root
.gitignore if the directory is moved.