To include all files in a directory, you must specify it as:
!directory/**
not with one asterisk ( * ).
Since you indicated to ignore all files
*.*
except for those that you included with bang ( ! ), you must correctly specify the files you want to add.
Background
As you can read in the specification , one asterisk corresponds to files directly in the directory. Not files in subdirectories.
In order not to ignore all the files in the directory, you need to use two consecutive asterisks:
Two consecutive asterisks (" ** ") in patterns mapped to full paths may have special meaning:
The leading " ** " followed by a slash in all directories. For example, “ **/foo ” matches the file or directory “foo” anywhere, the same as the template “ foo ”. " **/foo/bar " corresponds to the file or directory " bar " somewhere just below the directory " foo ".
The final " /** " matches everything inside. For example, " abc/** " matches all files inside the " abc " directory with respect to the location of the .gitignore file with infinite depth.
A slash followed by two consecutive asterisks, then a slash corresponds to zero or more directories. For example, " a/**/b " matches " a/b ", " a/x/b ", " a/x/y/b ", etc.
Other consecutive sprockets are considered invalid.
source share