Last updated
Quick Reference: Glob Syntax
*— matches any characters within a single path segment (no slashes)**— matches any characters including path separators (recursive)?— matches exactly one character (not a slash)[abc]— matches any one of the listed characters[a-z]— matches any character in the range{js,ts}— matches either js or ts (brace expansion)!— negates a pattern (in .gitignore and some tools)/at start — anchors to root directory (in .gitignore)/at end — matches directories only (in .gitignore)
Examples
Example 1: Basic Wildcard Patterns
Pattern: *.js
Matches:
✅ index.js
✅ app.js
✅ utils.js
Does NOT match:
❌ src/index.js (subdirectory — use **/*.js for recursive)
❌ index.jsx
❌ index.ts
Pattern: *.{js,ts}
Matches:
✅ index.js
✅ app.ts
✅ utils.js
Does NOT match:
❌ src/index.js
❌ index.jsx
❌ index.tsx
Example 2: The Critical Difference Between * and **
Pattern: src/*.js
Matches:
✅ src/index.js
✅ src/app.js
Does NOT match:
❌ src/utils/helpers.js (one level deep — need **)
❌ src/components/Button.js
Pattern: src/**/*.js
Matches:
✅ src/index.js
✅ src/utils/helpers.js
✅ src/components/Button.js
✅ src/components/forms/Input.js
✅ src/deeply/nested/path/file.js
Example 3: .gitignore Patterns
# Ignore all .log files anywhere in the repo
*.log
Matches: error.log, logs/app.log, deep/path/debug.log
# Ignore node_modules directory
node_modules/
Matches: node_modules/ (directory only, not a file named node_modules)
# Ignore build output at root only
/dist
Matches: dist/ (root only)
Does NOT match: packages/app/dist/
# Ignore all .env files except .env.example
.env*
!.env.example
Matches: .env, .env.local, .env.production
Does NOT match: .env.example (negation)
# Ignore all files in any __pycache__ directory
**/__pycache__/
Matches: __pycache__/, src/__pycache__/, deep/path/__pycache__/