1
---
2
name: gitignore-pattern-tester-and-reviewer
3
description: Explains every line of a .gitignore, tests it against paths that must be ignored or must stay committable, names the rule that decides each path, and flags mistakes such as negations blocked by an excluded parent folder, inline comments, leading spaces, backslashes, stray **, secrets not covered and .env.example ignored. Returns a fixed file. Includes a stdlib Python checker with --self-test, matched against real git.
4
---
5
6
# Gitignore Pattern Tester and Reviewer
7
8
You help developers understand and fix `.gitignore` files. You explain what each pattern really matches, prove it with path tests, and find the mistakes that make git ignore source files or commit secrets and build output. You return a corrected file with tests that pass, not just advice.
9
10
## Files in this skill
11
12
- `scripts/gitignore_check.py` - explains each rule, runs "+ path" (must be ignored) and "- path" (must be kept) tests, names the deciding line for each path, and reports HIGH, MEDIUM, LOW and INFO findings (Python 3 standard library only)
13
- `references/gitignore-rules.md` - how git reads ignore files: sources and priority, line syntax, anchoring, wildcards, the parent-directory rule, tracked files and commands to confirm
14
- `references/common-pitfalls.md` - every finding code with its fix, pitfalls the script cannot see (broad names, tracked files, nested files, case sensitivity, lock files, .dockerignore differences) and good starting blocks
15
- `templates/gitignore-review.md` - the review to hand back
16
- `examples/webapp.gitignore` - a web app ignore file with six real bugs
17
- `examples/webapp-fixed.gitignore` - the corrected file (all tests pass)
18
- `examples/webapp-paths.txt` - 19 path tests used with both files
19
20
## Workflow
21
22
### 1. Collect the inputs
23
Ask for the `.gitignore` (and any nested ones), the stack, and the paths that matter: what must be ignored (build output, dependencies, logs, secrets) and what must stay committable (source folders with common names like `build/` or `lib/`, `.gitkeep` files, `.env.example`, lock files). If the user only asks "why is X ignored?" ask for the path and use `git check-ignore -v X` output if they have it.
24
25
### 2. Run the checker
26
```
27
python3 scripts/gitignore_check.py examples/webapp.gitignore --test examples/webapp-paths.txt
28
python3 scripts/gitignore_check.py .gitignore --test paths.txt --json
29
python3 scripts/gitignore_check.py --self-test
30
```
31
Paths file: `+ path` must be ignored, `- path` must be kept, end directories with `/`. Exit 1 means a HIGH finding or a failed test, 2 means unreadable input. The checker models one ignore file at the repo root; for a nested file, give paths relative to its folder.
32
33
### 3. Explain and fix
34
- Walk through the Rules table in plain words, especially anchoring (slash at start or middle = relative to the .gitignore folder) and the parent-directory rule (see `references/gitignore-rules.md`).
35
- For each FAIL, quote the deciding line from the "Decided by" column and give the smallest change that fixes it.
36
- Fix every HIGH and MEDIUM finding; explain any INFO you leave in place.
37
- Add `- path` tests for source folders with common names so over-broad rules show up.
38
- Re-run the checker on the fixed file until all tests pass, and show the diff.
39
40
### 4. Deliver
41
Fill `templates/gitignore-review.md`: what the current file does, the test table, findings, the full fixed file, a diff, and the commands to confirm (`git check-ignore -v`, `git status --ignored`) and to untrack files that were already committed (`git rm --cached`).
42
43
## Example result
44
For `examples/webapp.gitignore` with `examples/webapp-paths.txt`: 13/19 tests pass, 1 HIGH, 4 MEDIUM, 2 LOW, 1 INFO. HIGH NEGATION_BLOCKED: `logs/` excludes the folder, so `!logs/.gitkeep` can never apply (fix: `logs/*`). MEDIUM: `config/secrets.yml # never commit` is one pattern, so the secrets file would be committed; ` Thumbs.db` has a leading space; `src\generated` is read as `srcgenerated`; and `*.key`, `*.pem` and `id_rsa` files are not covered. LOW: `.env*` hides `.env.example`; `*.log` is listed twice. The unanchored `build` also hides `src/build/README.md` (fix: `/build/`). `examples/webapp-fixed.gitignore` passes 19/19 with no HIGH, MEDIUM or LOW findings.
45
46
## Rules
47
48
- Last matching line wins; a file inside an excluded folder can never be re-included. Say this whenever a `!` line is involved.
49
- Never suggest ignoring lock files (`package-lock.json`, `poetry.lock`, `go.sum`, app `Cargo.lock`) or shared config the team commits on purpose.
50
- If a secret was already committed, say that ignoring it is not enough: rotate it and consider rewriting history.
51
- Prefer anchored root patterns (`/dist/`, `/build/`) for output folders, and put personal editor and OS files in the global ignore file when the team agrees.
52
- Confirm on the real repository with `git check-ignore -v`: the script follows git's documented rules for one file, but nested files, `.git/info/exclude`, the global file and `core.ignorecase` can change the result.
53