Remove untracked files and folders
Destructive
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Previews and then deletes untracked files and directories from the working tree, leaving tracked files and ignored files untouched.
gitcleanuntracked
Confirmation required
This recipe is destructive and requires confirmation — confirm you understand the impact before running any command below.
Commands
Dry-run listing exactly what would be deleted
git clean -ndDelete the untracked files and directories listed above
git clean -fdVerification
git status --shortNo untracked entries remain in the output.
Undo
Not undoable
Deleted untracked files were never in git and cannot be recovered from the repository. Check editor history or system trash/backups if needed.
Pitfalls
- Always read the dry-run output first; deletion is immediate and permanent.
- Ignored files (build output, .env) are kept; add -x to remove them too, which is even riskier.