git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] gitignore: rewrite wildcard description

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 3, 2026, 22:40 UTC
Message-ID
<xmqqh5hx4jz3.fsf_-_@gitster.g>
In-Reply-To
<xmqq5wyjxgyn.fsf@gitster.g>

The documentation for '.gitignore' makes reference to fnmatch(3) and FNM_PATHNAME to describe how an asterisk "*" and a question mark "?" behave. Even though it spells out that these wildcard characters do not match a slash, it does not say if an asterisk matches an empty string (it does).

Rewrite the section so that the readers would get a more complete picture without requiring them to know what fnmatch(3) and glob(7) says.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * let's adopt the most explicit "(including the empty string)"
   from glob(7).
 Documentation/gitignore.adoc | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
index 7979e50f18..87f37c2b0c 100644
--- a/Documentation/gitignore.adoc
+++ b/Documentation/gitignore.adoc
@@ -110,11 +110,16 @@ PATTERN FORMAT
    and `a/frotz` that is a directory (all paths are relative from
    the `.gitignore` file).
 
- - An asterisk "`*`" matches anything except a slash.
-   The character "`?`" matches any one character except "`/`".
-   The range notation, e.g. `[a-zA-Z]`, can be used to match
-   one of the characters in a range. See fnmatch(3) and the
-   FNM_PATHNAME flag for a more detailed description.
+ - An asterisk "`*`" matches any string (including the empty string),
+   and a question mark "`?`" matches any single character, but these
+   wildcard characters do not match a slash "`/`".
+
+ - A pair of brackets that enclose characters match one of the listed
+   characters, and a range notation inside them, e.g., "`[a-zA-Z]`",
+   would behave as if all the characters in the range were listed there
+   instead.  Wildcard characters "`*`" and "`?`" lose their special
+   meaning inside a pair of brackets, e.g., "`[*]`" would match an
+   asterisk and nothing else.
 
  - A backslash ("`\`") can be used to escape any character. E.g., "`\*`"
    matches a literal asterisk (and "`\a`" matches "`a`", even though

Interdiff:
  diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
  index 671a5a4c99..87f37c2b0c 100644
  --- a/Documentation/gitignore.adoc
  +++ b/Documentation/gitignore.adoc
  @@ -110,9 +110,9 @@ PATTERN FORMAT
      and `a/frotz` that is a directory (all paths are relative from
      the `.gitignore` file).
   
  - - An asterisk "`*`" matches string of any length, and a question mark
  -   "`?`" matches any single character, but these wildcard characters
  -   do not match a slash "`/`".
  + - An asterisk "`*`" matches any string (including the empty string),
  +   and a question mark "`?`" matches any single character, but these
  +   wildcard characters do not match a slash "`/`".
   
    - A pair of brackets that enclose characters match one of the listed
      characters, and a range notation inside them, e.g., "`[a-zA-Z]`",
-- 
2.56.0-511-g14903f623d
Previous: Tuomas Ahola
Message 7 of 7 in “Q: .gitignore and asterisk "*"”
  1. Windl, UlrichOct 30, 2026
  2. Junio C HamanoOct 30, 2026
  3. Tuomas AholaNov 3, 2026
  4. Windl, UlrichNov 3, 2026
  5. Junio C HamanoNov 3, 2026
  6. Tuomas AholaNov 3, 2026
  7. gitignore: rewrite wildcard descriptionJunio C Hamano, Nov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.