What does git rm --cached do, and when would you use it?
Last updated
git rm --cachedremoves a file from the index (stops tracking it) but keeps it on disk, unlike plaingit rmwhich deletes it too.Use it when you accidentally committed something like
.envor build artifacts. Pair it with a.gitignoreentry so it isn't re-added.Use
-rfor directories. Past commits still contain the file (purge withgit filter-repo).
- https://timmousk.com/blog/git-rm-cached/
- https://dev.to/ruqaiya_beguwala/day-2030-git-rm-cached-remove-files-from-staging-but-keep-locally-52l3
- https://medium.com/from-the-scratch/git-commands-you-need-to-know-when-you-are-messed-up-e880fbf03819
- https://git-scm.com/docs/git-rm
- https://www.kernel.org/pub/software/scm/git/docs/git-rm.html
- https://www.freecodecamp.org/news/learn-how-to-use-git-and-github-a-beginner-friendly-handbook/
- https://www.freecodecamp.org/news/git-cheat-sheet-helpful-git-commands-with-examples/
- https://medium.com/@ruqaiya.beguwala/day-20-30-git-rm-cached-remove-files-from-staging-but-keep-locally-d5180b0af0cc