How to Test .gitignore and Glob Patterns Before They Bite You
Why a .gitignore rule does not work, how Git, Docker and glob libraries read patterns differently, and how to test rules against real file paths.

Glob patterns quietly control a lot of a developer's day. A .gitignore decides what reaches the repository, a .dockerignore decides what goes into an image, and globs in tsconfig, ESLint, Prettier and build scripts decide which files get compiled, checked or copied. When a pattern is wrong, the failure is often silent: a secret file committed, a 2 GB node_modules folder sent to the Docker daemon, or a test file shipped in a package.
The rules that trip people up
Slashes change everything in a .gitignore. A pattern without a slash, such as build or .log, matches a name at any depth. A pattern with a slash at the start or in the middle, such as /build or docs/.pdf, is tied to the folder that holds the .gitignore. A trailing slash, as in temp/, means folders only.
The last matching line wins. If *.log ignores a file and a later !important.log matches it, the file is kept.
Ignored folders are final. Git never looks inside an ignored folder, so a later rule like !logs/keep.txt cannot bring a file back if logs/ itself is ignored. Ignore the contents instead with logs/** or logs/*, then add the exception.
Docker is different. In a .dockerignore every pattern starts at the root of the build context, a trailing slash means nothing special, and exceptions can re-include a file even inside an excluded folder.
Plain globs skip dotfiles. In most glob libraries, * and do not match names that start with a dot unless a dot option is turned on, so src//.js misses src/.cache/x.js. Also, a single never crosses a slash.
Testing rules against real paths
The Glob Pattern and .gitignore Tester shows the effect of every line instantly. Pick .gitignore, .dockerignore or glob list mode, then type the rules or open your existing file. For paths, the most realistic source is your own project: run git ls-files, or find . -type f on macOS and Linux, and paste the output. Alternatively, pick the project folder. The browser hands the page only the relative file names; no file is opened or uploaded.
Each path is marked ignored or kept, or selected or not in glob mode, next to the exact line that decided it. When the reason is a parent folder, a note says which one. In the editor gutter, every rule shows how many paths it decided, and rules that decided nothing are shown in red. Dead rules are usually typos, leftovers from removed tools, or patterns anchored to the wrong folder.
Turn on Also list the folders to add each folder on the way to every file. That makes it obvious which folder rule did the work, for example that packages/web/node_modules/ was caught by node_modules/ on line 2.
Reading the compiled patterns
Under the results, each rule is shown after anchoring, for instance .log becomes */.log, together with the regular expression it compiles to. This is the best way to understand features such as brace expansion ({ts,tsx} or {1..5}), character classes ([a-c], [!0-9], [[:digit:]]) and extglobs (@(a|b), !(.min).js), which are supported in glob mode.
A short checklist for a clean .gitignore
- Use node_modules/ without a leading slash so nested packages are covered too.
- Anchor build output to the root with /dist or /build, so a src/build folder is not ignored by accident.
- Keep secrets out with .env and bring examples back with !.env.example.
- For folders where one file must stay, ignore the contents (folder/*) rather than the folder.
- Remove rules that decide nothing.
When to double-check with Git itself
The tester follows the documented rules, but real repositories add layers: .gitignore files in sub-folders, a global excludes file, and core.ignorecase on case-insensitive file systems. For a definitive answer on a specific file, git check-ignore -v path prints the file and line that ignored it. Use the tester to design and clean up the rules, and Git to confirm the edge cases.



