# Git Rm Cached: stop tracking a file and keep it on disk

Published: 2026-11-30
Updated: 2026-12-03

Rights: original
Source: https://kairospan.com/res/git-rm-cached-full-en
Stop tracking a file and keep it on disk: `git rm --cached FILE` removes it from the index, so the next commit no longer carries it.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-79-A, TE-79-B and TE-79-C. The expected non-zero exit is TE-79-C (exit status 128). Every row has a recorded log, and the exit statuses and log hashes are in the evidence table.)

Q: How do I stop tracking a file without deleting it?
A: git rm --cached with the path. It untracks the file and leaves it on disk.

Q: Is the file still there after the commit?
A: Yes. After rm --cached and a commit, git tracks no file and the file is still on disk.

Q: Why does git rm --cached fail on a file git does not track?
A: There is no tracked entry to remove. git stops with a fatal error.

### TE-79-A: rm --cached untracks a file but the file stays on disk

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git rm -q --cached f.txt; echo tracked=$(git ls-files f.txt | wc -l); echo on_disk=$([ -f f.txt ] && echo yes || echo no); git status --porcelain
```

Recorded output:

```
tracked=0
on_disk=yes
D  f.txt
?? f.txt
```

Exit status: 0. The output matches the expected text written before the run.

### TE-79-B: after rm --cached and a commit, git tracks no file and the file is still on disk

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git rm -q --cached f.txt; git commit -qm gone; echo tracked=$(git ls-files | wc -l); ls
```

Recorded output:

```
tracked=0
f.txt
```

Exit status: 0. This status and the output match what was written before the run.

### TE-79-C: expected non-zero exit: rm --cached on a path git does not track stops with a fatal error

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git rm -q --cached nosuch.txt
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
fatal: pathspec 'nosuch.txt' did not match any files
```

Exit status: 128. This status and the output match what was written before the run.

TE-79-B: after git rm --cached and a commit, git ls-files lists no file, so tracked=0, and ls still shows f.txt. TE-79-C: git rm --cached nosuch.txt exited with status 128, and standard error reads fatal: pathspec 'nosuch.txt' did not match any files.

## Limits

The run uses one file. Removing a directory (`-r`) and the effect on other clones were not tested. Not tested on this page: `-n` (only simulate the removal), `-f` (override the up-to-date check), `--ignore-unmatch` (exit with a zero status even when nothing matched), `--pathspec-from-file` (read the pathspec from a file) and `--pathspec-file-nul` (separate the pathspec elements with a NUL character). The names and one-line descriptions come from `git rm -h` in git 2.34.1. No `git rm` command here used them.

## Source

- https://git-scm.com/docs/git-rm

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-79-A` | rm --cached untracks a file but the file stays on disk | 0 | PASS | `81cc8141b582` |
| `TE-79-B` | after rm --cached and a commit, git tracks no file and the file is still on disk | 0 | PASS | `c7fc814dc412` |
| `TE-79-C` | expected non-zero exit: rm --cached on a path git does not track stops with a fatal error | 128 | PASS | `bcb6b6cab5fa` |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC.
Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Git mv: rename a tracked file or move it into a folder](https://kairospan.com/res/git-mv-full-en)
- [Git Grep: search tracked files](https://kairospan.com/res/git-grep-full-en)
- [Git Shortlog: commits per author](https://kairospan.com/res/git-shortlog-full-en)
- [git revert: undo a commit by adding a new one](https://kairospan.com/res/git-revert-full-en)
- [Git show: read one commit, its message and its files](https://kairospan.com/res/git-show-full-en)
