.GITIGNORE EXPLAINER · RUNS IN YOUR BROWSER · NOTHING UPLOADED

Why is git ignoring this file, and why doesn't my ! rule work?

Paste your .gitignore files and a list of paths. For every path you get the rule that decides it, resolved the way git resolves it: last match wins, deeper files beat shallower ones, and git never looks inside an ignored folder, which is why build/ followed by !build/keep.txt does nothing. The tool finds those dead negations, writes a fix it has checked against your list, and lists tracked files your rules match but cannot touch.

Nothing you paste leaves this browser tab. Checked against git check-ignore on thousands of random repositories (see the README); still, your own git is the final word.

1. Your ignore files

Paste your root .gitignore. For more files, start each with a line ==> path/to/.gitignore <== (what head prints for several files, so head -n 1000 $(git ls-files '*.gitignore') gives you the whole lot). ==> .git/info/exclude <== works too.

One corner changed in git 2.52: a ** glued to literal text, as in /a**/b, crossed folders before and acts like * now. Everything else matches the same in both.

2. The paths to check

From git ls-files --others, or git status --porcelain --ignored, or typed by hand. End a line with / to mark a folder.

From git ls-files. Ignore rules have no effect on these; the tool lists the ones your rules match.

Why is one path ignored?

The steps git takes, folder by folder, using the ignore files above.

    From a terminal

    The same engine runs over a whole repository, with no install and no network: it reads every .gitignore, .git/info/exclude, and the tracked and untracked file lists itself.

    node ventures/gitignore-explainer/cli/check.mjs            # report
    node ventures/gitignore-explainer/cli/check.mjs --why path # the steps for one path
    node ventures/gitignore-explainer/cli/check.mjs --strict   # exit 1 on a high finding (CI)

    Clone the source, then run it from inside your own repository with the path to cli/check.mjs. Node 18 or later.

    Questions

    Why does my ! negation in .gitignore not work?

    Almost always because a folder above the file is ignored. Git does not look inside an ignored folder at all, so it never reads a rule about a file inside it. With build/ followed by !build/keep.txt, the folder build is ignored and keep.txt is never considered. Ignore the folder's contents instead, with build/* followed by !build/keep.txt, and re-open each deeper folder on the way down with a rule like !build/sub/.

    Which rule is ignoring my file?

    Git checks the rules from the last line up and the first one that matches decides. A .gitignore in a deeper folder is checked before the one above it, and .git/info/exclude and your global excludes file come last. The command git check-ignore -v path prints the deciding rule for one path; this tool does the same for every path in your list at once, and explains folder-by-folder when an ignored parent folder is the reason.

    Why is a file still showing up in git status after I added it to .gitignore?

    Because it is already tracked. Ignore rules only apply to files git is not tracking yet. Run git rm --cached on the file to stop tracking it while keeping it on disk, then commit. Paste your git ls-files output into the tracked box and the tool lists every tracked file your rules match.

    When does a .gitignore pattern match only at the top level?

    When it contains a slash anywhere except at the very end. docs/*.pdf matches only docs at the top of the folder the .gitignore lives in, while *.pdf or a pattern with only a trailing slash, like logs/, matches at any depth. To match a path with a slash at any depth, start it with **/, as in **/docs/*.pdf.

    What does ** mean in .gitignore?

    Two asterisks cross folders only when they fill a whole path segment: **/name matches name in any folder, name/** matches everything inside name, and a/**/b matches b at any depth below a, including directly inside it. Glued to other characters, as in src/**.js, the two asterisks act like one and stop at the next slash.

    Can I put a comment at the end of a .gitignore line?

    No. A line is a comment only when it starts with #. Anything after a pattern, including # and the words after it, becomes part of the pattern, so the rule stops matching what you meant. Trailing spaces are trimmed but tabs are not, and leading spaces count. The tool flags all of these.

    Is anything I paste uploaded?

    No. The checker runs entirely in this browser tab. There are no accounts, cookies or analytics vendors, and the command-line version makes no network calls.