What does git clean do?
git clean removes untracked files and directories from the working tree.
What counts as untracked
- files that are not added to Git
- files that are not in any commit
- temporary files, build artifacts, logs, and so on
What the command does
bash
git clean -f- removes untracked files
- does not touch committed files
- does not change history
Commonly used options
bash
git clean -nShows what would be removed, without removing anything (a dry run).
bash
git clean -fRemoves untracked files.
bash
git clean -fdRemoves untracked files and directories.
bash
git clean -fxAlso removes files ignored via .gitignore.
What git clean does NOT do
- does not remove modified but tracked files
- does not undo changes in tracked files
- does not affect commits or history
Important
git clean permanently deletes files.
It is recommended to first use:
bash
git clean -nKey phrasing for an interview
git cleanremoves untracked files and directories from the working tree. The command does not change the commit history, but it can lead to data loss, so it is usually used with a preview first.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.