gritHEAD → docs/rm
Commands / Making changesMarkdown

grit rm

Remove tracked paths from the working tree and index.

grit rm [--cached] [-f|--force] [--dry-run] [--ignore-unmatch] [--pathspec-from-file <file|->] [--pathspec-file-nul] <path>...

Description

Removes tracked files or directories from the index and, by default, from the working tree. Pathnames in human and --markdown output use the same quoting rules as grit status (see Description there). With --cached, the file stays on disk as an untracked file but is removed from the index.

Grit refuses to remove a path when doing so would lose content that is stored nowhere else, unless you pass --force. The rules match Git's safety rules for git rm:

The path has… grit rm grit rm --cached
No changes since HEAD removed removed
Local modifications (the file differs from the index) refused removed, file kept
Staged changes (the index differs from HEAD, or there is no commit yet) refused removed, file kept
Staged content that differs from both HEAD and the file refused refused
A file already deleted from the working tree removed removed

So the usual way to stop tracking an accidentally committed file (.env, build output) works even after you edited it: grit rm --cached .env keeps your copy on disk and stages the deletion. When a path is refused, nothing is changed; the error lists each refused path with its reason and suggests --cached only when it would help.

Directory pathspecs remove every tracked file under that directory; trailing slashes on a directory path (or a path that names an existing directory) imply recursive removal. Attribute pathspecs such as :(attr:myattr) use the same .gitattributes stack as grit log (including with --cached).

--dry-run runs the same checks and lists paths that would be removed without writing the index or work tree. --ignore-unmatch treats non-matching pathspecs as success with an empty result (like git rm --ignore-unmatch).

Options

Option Description
<path>... Files or directories to remove (required unless --pathspec-from-file is set).
--pathspec-from-file Read pathspecs from a file, or - for stdin (same rules as Git).
--pathspec-file-nul With --pathspec-from-file, entries are NUL-separated instead of line-based.
--cached Remove from the index only; keep the working tree copy.
-f, --force Remove even when the safety rules above would refuse the path.
--dry-run Preview removals without changing the index or work tree.
--ignore-unmatch Do not error when a pathspec matches nothing.

JSON output

Schema: v1

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

Field Type Meaning
removed array of strings Repository-relative paths removed from the index (and work tree unless --cached), or that would be removed when --dry-run is set.
dry_run boolean true when --dry-run was passed.

Markdown output

Exit status

Code Meaning
0 Success (success).
1 Command failed (failure), including a refusal by the safety rules; with --json the refusal is an {"error": "..."} object listing the refused paths.
2 Invalid flags or arguments (usage).

See Exit codes for shared rules and structured --json kind values.