Referring to the online docs:
If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).
To me, this documentation says that given a pattern 'foo', any file or directory named 'foo' will be ignored only relative to the .gitignore file. I don't read anything explaining its recursive behavior. Shell globs (from what I read and experience) are not recursive.
Now further below it explains the double asterisk:
A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo"
so yes there is an example in the docs explaining that **/foo
is equal to foo
, but the recursive behavior remains implicit.
The recursive nature of a rule like "
foo
" is derived from the way those rules are fetched and applied:So even multiple sub-directories below a .gitignore, the rule "
foo
" will still apply to any "foo
" file found in said sub-folder.