What is git rm?
Why Interviewers Ask This
This is a classic screening question for Git & GitHub roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
git rm removes files from both the working directory and the Git staging area (index), staging the deletion for the next commit. It is different from simply deleting a file with rm — if you delete a file manually, you still need to git add the deletion; git rm does both in one step. Usage: git rm file.txt — delete from working directory and stage the deletion; git rm -r dir/ — recursively remove a directory; git rm --cached file.txt — CRITICAL: removes the file from tracking (index) WITHOUT deleting from disk. Used when you accidentally committed a file that should be in .gitignore (secrets, node_modules). After git rm --cached, add the file to .gitignore and commit the removal; git rm -f file.txt — force removal even if file has uncommitted changes; git rm "*.log" — remove files matching a pattern. After git rm, the deletion is staged — commit to finalize: git commit -m "Remove obsolete file". Common workflow: accidentally committed .env file → git rm --cached .env → add to .gitignore → commit → rotate any exposed secrets.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.