git ignore all files of a certain type, except those in a specific subfolder

An optional prefix ! which negates the
pattern; any matching file excluded by
a previous pattern will become
included again. If a negated pattern
matches, this will override lower
precedence patterns sources.

https://git-scm.com/docs/gitignore

*.json
!spec/*.json

Leave a Comment