When git processes wildcards it is supposed to match files at any level. The reason that you are seeing this behaviour is because the shell expands *.c
to an explicit list of files if that wildcard matches in the current directory. In this case Git sees and explicit list of .c
files, not a wildcard.
If the shell fails to expand *.c
because no files in the current directory match that pattern then the wildcard pattern is passed unexpanded to Git which performs the expansion itself and matches in subdirectories.
If you are using bash you can use shopt -s nullglob
to make the shell expand the wildcard to empty, or shopt -s failglob
to produce an error and not run git add
if the pattern doesn't match.