.gitignore patterns.
Quick Reference
Quick Reference
| Token | Meaning |
|---|---|
* | any run of characters except / |
** | zero or more path segments |
{a,b} | brace expansion – either a or b |
!pattern | negation – exclude matches |
? | exactly one character except / |
[...] | one character from the set / range |
Examples of Common Patterns
Some everyday use cases for globs:| Use‑case | Pattern |
|---|---|
| All files at any depth | ** |
| All markdown files at any depth | **/*.md |
All files in src/ | src/** |
All TypeScript & TSX in src/ | src/**/*.{ts,tsx} |
| Only test files (Jest style) | **/*.{test,spec}.{ts,tsx} |
Everything except node_modules | ** !**/node_modules/** |
Basic Patterns
Wildcard *
* matches any string within a path segment, but not across directory boundaries.
Globstar **
** matches any string (including empty) across directory boundaries. Using ** is the most common way to match all files in a directory.
Brace expansion {a,b}
Expands into multiple literal alternatives before matching.
So, src/**/*.{ts,tsx} expands into two patterns: src/**/*.ts and src/**/*.tsx
Negation !pattern
Prefix a pattern with ! to exclude it.
Negation is usually used in conjunction with multiple patterns.Patterns are evaluated in the order they are listed. So, you typically want your first pattern to be the most inclusive, followed by a series of negations.
Combining Brace Expansion and Negation
Combining Brace Expansion and Negation
Extras
These are less commonly used, but useful to know about.Character class `[...]`
Character class `[...]`
Match exactly one character from a set or range.
Single‑char wildcard `?`
Single‑char wildcard `?`
? matches exactly one character (except /).Extglobs: `@() !() ?() +() *()`
Extglobs: `@() !() ?() +() *()`
Extglobs are parenthesized patterns preceded by a single symbol that changes how many times the sub‑pattern(s) may appear.
Think of them as “mini‑regular‑expressions” you can drop directly inside a glob.
Inside the parentheses separate alternatives with pipes (Using Using Using Using
Think of them as “mini‑regular‑expressions” you can drop directly inside a glob.
| Syntax | Meaning | Handy mnemonic |
|---|---|---|
@(p1|p2) | Exactly one of the alternatives | “At” least one – exactly one |
?(p) | Zero or one occurrence of the pattern | The ? you already know means “maybe” |
+(p) | One or more occurrences | + in regex = “one or more” |
*(p) | Zero or more occurrences | * in regex = “zero or more” |
!(p) | Anything except the alternatives | ! = “not” |
|): @(foo|bar|baz).Quick examples
Using@ with extglobs:! with extglobs:* with extglobs:? with extglobs:+ with extglobs:Ellipsis custom handling
To cover some edge cases we commonly see in production, we have some custom handling of glob patterns to reduce footguns.Forgetting to append /**
It’s common for developers to reach for .gitignore-style patterns, which don’t require using the globstar **. So, we expand patterns that don’t end in /** to include all files in the directory.
src => src/**
src/ => src/**
Dot‑files
Although dotfiles are commonly excluded by default in many globbing tools, Ellipsis enables them by default.Negation without matching patterns
It’s a common mistake to include a negation pattern without any matching patterns before it. So, if all patterns in a list are negated, Ellipsis will automatically insert a** pattern to run first in the list to ensure some files are included.
Triple stars (***)
Using *** is usually a typo where the user meant to write **. So, we rewrite them to **.
*** => **
src/***/foo => src/**/foo