# grit ignore

> Query whether paths match exclude (gitignore) rules.

## Synopsis

```text
grit ignore check <PATH>...
grit ignore check --all <PATH>...
```

## Description

The `check` subcommand reports whether paths are ignored by `.gitignore`, `.git/info/exclude`, and `core.excludesfile`, using the same precedence as Git. Tracked index entries are never treated as ignored. When `core.ignorecase` is `true` (`grit init` sets it on case-insensitive filesystems, such as the Windows and macOS defaults), patterns match without regard to ASCII case, as in Git: `Build/` ignores `build/x.o` and `*.LOG` ignores `debug.log`. [`grit status`](https://grit-scm.com/docs/ignore/status.md/index.md), [`grit add`](https://grit-scm.com/docs/ignore/add.md/index.md), [`grit commit`](https://grit-scm.com/docs/ignore/commit.md/index.md) and [`grit clean`](https://grit-scm.com/docs/ignore/clean.md/index.md) use the same rules.

By default only **ignored** paths are printed. Pass `--all` to also list paths that are not ignored.

Paths are resolved from the current directory and normalized within the worktree. They do not need to exist; a trailing `/` marks a directory query. Batch queries reuse the resolved worktree root when normalizing paths.

The command exits with status **0** when at least one path is ignored, and **1** when none are. Scripts can branch on this exit code.

Human output uses a verbose-style line per ignored path:

```text
path  ← .gitignore:3 *.log
```

## Options

| Option | Description |
| --- | --- |
| `--all` | Also print paths that are not ignored. |
| `<PATH>` | One or more paths (from the current directory or repository-relative). |

## Examples

Query a single ignored file:

```console
$ grit ignore check build/output.log
build/output.log  ← .gitignore:1 *.log
```

List ignored and non-ignored paths:

```console
$ grit ignore check --all src/main.rs tmp/cache/
src/main.rs
tmp/cache/  ← .gitignore:2 tmp/
```

Exit status when nothing matches:

```console
$ grit ignore check tracked.txt; echo $?
1
```

## JSON output

Schema: [v1](https://grit-scm.com/docs/ignore/schemas/ignore.check/v1.json/index.md)

Pass `--json` for stable, scripting-friendly output:

| Field | Type | Meaning |
| ----- | ---- | ------- |
| `any_ignored` | boolean | `true` when at least one queried path is ignored. |
| `entries` | array | Filtered results (ignored only unless `--all`). |
| `entries[].path` | string | Repository-relative path. |
| `entries[].ignored` | boolean | Whether the path is ignored. |
| `entries[].matched` | object or omitted | Verbose match metadata when present. |
| `entries[].matched.source` | object | Typed source (`per_directory`, `info_exclude`, or `core_excludes_file`). |
| `entries[].matched.line_number` | number | 1-based line in the source file. |
| `entries[].matched.pattern_text` | string | Pattern text as written in the file. |
| `entries[].matched.negative` | boolean | Whether the rule is negated (`!pattern`). |

Example:

```json
{
  "any_ignored": true,
  "entries": [
    {
      "path": "build/output.log",
      "ignored": true,
      "matched": {
        "source": {
          "kind": "per_directory",
          "path": ".gitignore"
        },
        "line_number": 1,
        "pattern_text": "*.log",
        "negative": false
      }
    }
  ]
}
```

## Markdown output

Schema: [v1](https://grit-scm.com/docs/ignore/schemas/ignore.check/v1.json/index.md)

Pass `--markdown` for agent-friendly output with the same fields summarized in prose and lists.




```text
## Ignore check

- **any_ignored:** true

- `noise.log` ← `.gitignore:1` `*.log`
```

## Exit status

| Code | Meaning |
| ---: | --- |
| `0` | At least one path is ignored (`ignore check`). |
| `1` | No matching ignored paths. |
| `2` | Invalid flags ([`usage`](https://grit-scm.com/docs/exit-codes/index.md)). |

See [Exit codes](https://grit-scm.com/docs/exit-codes/index.md).


## See also

- [`grit clean`](https://grit-scm.com/docs/ignore/clean.md/index.md) — remove untracked files (optionally including ignored paths with `--ignored`).
- [`grit status`](https://grit-scm.com/docs/ignore/status.md/index.md) — working tree summary.
