Ad space (banner)
🌿Git Lessons
Lesson 17 / 59

Untracking a File with git rm

This lesson covers removing a file from Git's tracking with git rm. It's for anyone searching "git rm --cached usage."

git rm removes a file from Git's management. Add the --cached flag and only Git's tracking is dropped, while the actual file stays right where it is.

In Try It, run git rm --cached app.js. The actual file app.js stays on your computer untouched, while it's removed from Git's history tracking.

A common early mistake is forgetting the --cached flag — without it, the actual file gets deleted too, so pay attention to make sure the outcome matches what you actually intended. In real teams, this command comes up for something like accidentally committing a secret file before setting up .gitignore, and needing to remove it from tracking.

Git
Try it (type this into the pseudo terminal)
git rm --cached app.js

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)