This seems like an obscure git
bug to me — !directory**/**
is an invalid usage of consecutive asterisks as per the manual, but it doesn't state how such invalid rules are handled.
The correct rules should be:
*
!directory/
!directory/**
The reason is that *
matches all files regardless of the directory they're in (because it does not contain a slash), so !directory/
will only allow the directory itself, but not its contents — you need to add !directory/**
to match them as well. Using just !directory/**
without !directory/
won't work, as !directory/**
does not match the directory
itself and it will remain ignored.
Edited: !directory/
is preferrable to !directory
(without a trailing slash), as !directory
will also match files and directories named directory
deeper in the directory tree; this will not affect your case, but might be a gotcha in more complex .gitignore
rulesets.