.gitignore tester

Check which paths a .gitignore file ignores and which line decided each one, using real Git matching rules.

Input

The contents of the .gitignore file.
Paths relative to the folder holding the .gitignore. End a path with / to mark it as a folder.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/gitignore-test \
  -H 'Content-Type: application/json' \
  -d '{"input":{"gitignore":"# logs and build output\n*.log\n/build/\n!important.log\ndocs/**/*.tmp","paths":["debug.log","important.log","build/app.js","src/build/app.js","docs/a/b/x.tmp"]}}'
import json, urllib.request

body = {'input': {'gitignore': '# logs and build output\n*.log\n/build/\n!important.log\ndocs/**/*.tmp', 'paths': ['debug.log', 'important.log', 'build/app.js', 'src/build/app.js', 'docs/a/b/x.tmp']}}
request = urllib.request.Request("https://setget.net/v1/tools/gitignore-test", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/gitignore-test", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"gitignore":"# logs and build output\n*.log\n/build/\n!important.log\ndocs/**/*.tmp","paths":["debug.log","important.log","build/app.js","src/build/app.js","docs/a/b/x.tmp"]}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "gitignore-test",
  "input": {
    "gitignore": "# logs and build output\n*.log\n/build/\n!important.log\ndocs/**/*.tmp",
    "paths": [
      "debug.log",
      "important.log",
      "build/app.js",
      "src/build/app.js",
      "docs/a/b/x.tmp"
    ]
  }
}
{
  "input": {
    "gitignore": "# logs and build output\n*.log\n/build/\n!important.log\ndocs/**/*.tmp",
    "paths": [
      "debug.log",
      "important.log",
      "build/app.js",
      "src/build/app.js",
      "docs/a/b/x.tmp"
    ]
  }
}

Endpoint: POST /v1/tools/gitignore-test. Over MCP: run_tool with slug: "gitignore-test". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
gitignore string yes The contents of the .gitignore file.
paths array yes Paths relative to the folder holding the .gitignore. End a path with / to mark it as a folder.

Examples

Input
{
  "gitignore": "# logs and build output\n*.log\n/build/\n!important.log\ndocs/**/*.tmp",
  "paths": [
    "debug.log",
    "important.log",
    "build/app.js",
    "src/build/app.js",
    "docs/a/b/x.tmp"
  ]
}
Result
{
  "results": [
    {
      "path": "debug.log",
      "ignored": true,
      "line": 2,
      "pattern": "*.log"
    },
    {
      "path": "important.log",
      "ignored": false,
      "line": 4,
      "pattern": "!important.log"
    },
    {
      "path": "build/app.js",
      "ignored": true,
      "line": 3,
      "pattern": "/build/"
    },
    {
      "path": "src/build/app.js",
      "ignored": false,
      "line": null,
      "pattern": null
    },
    {
      "path": "docs/a/b/x.tmp",
      "ignored": true,
      "line": 5,
      "pattern": "docs/**/*.tmp"
    }
  ],
  "ignored": [
    "debug.log",
    "build/app.js",
    "docs/a/b/x.tmp"
  ],
  "not_ignored": [
    "important.log",
    "src/build/app.js"
  ]
}

Ignore everything except one folder (from the Git manual)

Input
{
  "gitignore": "/*\n!/foo\n/foo/*\n!/foo/bar",
  "paths": [
    "readme.md",
    "foo/baz.txt",
    "foo/bar/x.txt"
  ]
}
Result
{
  "results": [
    {
      "path": "readme.md",
      "ignored": true,
      "line": 1,
      "pattern": "/*"
    },
    {
      "path": "foo/baz.txt",
      "ignored": true,
      "line": 3,
      "pattern": "/foo/*"
    },
    {
      "path": "foo/bar/x.txt",
      "ignored": false,
      "line": 4,
      "pattern": "!/foo/bar"
    }
  ],
  "ignored": [
    "readme.md",
    "foo/baz.txt"
  ],
  "not_ignored": [
    "foo/bar/x.txt"
  ]
}

Questions

Why does my "!" rule not bring a file back?
Git does not look inside an ignored folder, so a file cannot be re-included when one of its parent folders is ignored. Un-ignore the folder first.
When is a pattern tied to the top folder?
When it has a slash at the start or in the middle. A pattern without one, such as *.log, matches at any depth.
How do I say that a path is a folder?
End it with a slash. Patterns that end with a slash match folders only.
Are files already tracked by Git affected?
No. Ignore rules apply only to untracked files. This tool cannot see your repository.