Pattern syntax: .gitignore versus GitHub Actions paths
In one line: How `**`, `*`, `?` and `[]` differ between the two systems, and why paths and paths-ignore cannot be combined.
.gitignore and GitHub Actions paths both look like globs, but they are not the same language. Copying a .gitignore pattern into a workflow is how “the workflow never runs” and “the workflow runs for unrelated changes” incidents start.
Syntax comparison
| Token | .gitignore | GitHub Actions paths |
|---|---|---|
* | Any length except a slash | Zero or more characters except a slash |
** | Special only in **/, /** and /**/ positions; otherwise two ordinary stars | Any string, slashes included |
? | Exactly one character except a slash | Zero or one of the preceding character |
[a-z] | Character range | Character range |
!pattern | Re-include (last match wins) | Negate (last match wins) |
| Pattern without a slash | Matches a file name at any depth | Matches the full path from the repository root |
The last row causes the most surprises. *.md ignores markdown in every folder for git, but in Actions it matches only root-level files. To cover subfolders, write **.md.
paths and paths-ignore are mutually exclusive
on:
push:
paths:
- "src/**"
paths-ignore:
- "**.md" # error: not allowed in one trigger
Use negation inside paths instead.
on:
push:
paths:
- "src/**"
- "!**/*.md"
Order matters. If !**/*.md comes before src/**, the later pattern includes those files again. The debugger warns when both keys are present and shows the last-match-wins walk in the trace.
Confirming that a change triggers the workflow
Simulate with the real changed files. git diff --name-only origin/main...HEAD gives the paths, and pasting them into the test paths of this debugger shows which ones trigger a run and which are filtered out. Add a trailing / for directory paths.
Common traps
docs/*does not includedocs/a/b.md, because*does not cross a slash.- Editing the workflow file itself does not trigger a run unless
.github/workflows/**is in the paths. - Switching between
pathsandpaths-ignoremakes it hard to tell which one actually applied. Use one per file. - Branch filters and path filters are combined with AND: a matching path on another branch still does not run.
Put the same rules and paths into the debugger to see the winning line and the traps immediately.
Open GlobLabFrequently asked questions
What does `**` mean in Actions?
Any string including slashes. **.js matches js files in every folder and src/** matches everything under src.
`?` is not a single character?
In Actions filter patterns ? means zero or one of the preceding character. It is not bash glob, so patterns like file?.txt can behave unexpectedly.
Does listing a directory in paths include its files?
Write docs/** explicitly. Test both forms side by side in this debugger to see the difference.
Sources
Read next
- .gitignore order, re-includes, and the excluded-parent trapLast match wins, why a `!` re-include stops working under an excluded directory, and safer exception patterns, with examples.
- The rsync include/exclude first-match trapRule order in rsync, directory pruning, and a filter order that survives backups, with broken and fixed examples.
- .dockerignore versus .gitignoreTwo files with the same syntax and different scope, plus patterns that keep the build context small and reproducible.