opyebGlobLab

Pattern syntax: .gitignore versus GitHub Actions paths

GitHub Actions · 7 min read

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.gitignoreGitHub Actions paths
*Any length except a slashZero or more characters except a slash
**Special only in **/, /** and /**/ positions; otherwise two ordinary starsAny string, slashes included
?Exactly one character except a slashZero or one of the preceding character
[a-z]Character rangeCharacter range
!patternRe-include (last match wins)Negate (last match wins)
Pattern without a slashMatches a file name at any depthMatches 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 include docs/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 paths and paths-ignore makes 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 GlobLab

Frequently 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

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)