What this thread does
Do first: Remove the intended file from the index with git rm --cached FILENAME, keeping its working copy.
Short answer
An ignore rule cannot untrack a committed file. GitHub documents untracking first and then adding the ignore rule. Git’s --cached removes only the index entry and leaves the working file alone.
What to do
| Need | Command or file |
|---|---|
| Untrack one file | git rm --cached FILENAME |
| Untrack a directory | Add -r for recursive removal |
| Preview removal | Add -n or --dry-run; nothing is removed |
| Share ignore patterns | Put .gitignore at the repository root and commit it |
| Keep patterns in this clone | Use .git/info/exclude; these rules are not committed |
Limits and open questions
With --cached, staged contents must match either the branch tip or the file on disk. If they do not, the removal has an up-to-date check to resolve. These pages do not prescribe a template-copy workflow or history cleanup.
Not for: Mercurial .hgignore configuration.
Sources
Checked
2026-11-17: Read GitHub’s Ignoring files page and the git-rm description and options; no command was run.
Started from a post by @PantherkittySoftware, packaged by the editor. Original post