Suggest an editImprove this articleRefine the answer for “What is `git rm` used for?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`git rm`** is used to remove files from a Git repository while recording that removal for the next commit. **Key point:** the command removes the file from the working directory and immediately stages the removal in the staging area.Shown above the full answer for quick recall.Answer (EN)Image`git rm` is used to **remove files from a Git repository** while recording that removal for the next commit. That is, the command: - removes the file **from the working directory** - adds the removal to the **staging area** ## How `git rm` differs from plain `rm` | Action | File removed | Git knows about the removal | | --- | --- | --- | | `rm file.txt` | yes | no (needs `git add`) | | `git rm file.txt` | yes | yes | --- ## Basic usage ```bash git rm file.txt git commit -m "Remove unused file" ``` --- ## Main variants ### 1. Remove a file from the project completely ```bash git rm src/old.js ``` --- ### 2. Remove a file only from Git (keep it on disk) ```bash git rm --cached config.env ``` Useful when: - a file ended up in the repository by mistake - it needs to be added to `.gitignore` --- ### 3. Remove a directory ```bash git rm -r dist/ ``` --- ## Common use cases - Removing outdated files - Removing secrets from a repository - Cleaning up unnecessary artifacts from a project - Refactoring project structure --- ## Frequent mistakes - Using `rm` instead of `git rm` and forgetting `git add` - Removing a file without committing - Removing an important file without `--cached` --- ## Checking the state After removal: ```bash git status ``` Shows: ```text deleted: src/old.js ``` --- ## Short answer for an interview > `git rm` **removes a file from the working directory and at the same time stages its removal for a commit in Git.**For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.