Cheat Sheets · Git Cheat Sheet · Git Clean Untracked Files — Remove Clutter Safely

Git Clean Untracked Files — Remove Clutter Safely

git clean -n

Safe (Dry run)

git clean -fd

Destructive

git clean -fdx

Very Destructive

Git clean commands

CommandSafetyEffect
git clean -nSafe (Dry run)List files that would be removed without deleting anything
git clean -fdDestructiveForce delete untracked files and directories
git clean -fdxVery DestructiveAlso delete ignored files (e.g. node_modules, .env, build/)

Clean up build artifacts, temp files, and untracked junk from your working tree. Always start with a dry run to avoid deleting wanted files.

Related Git recipes

FAQ

Can I recover files deleted by git clean?
No! Because untracked files were never committed to Git, Git has no copy in its object database. Always dry-run with -n first.

What does the -d flag mean?
It instructs clean to remove untracked whole directories in addition to individual files.

How to clean only a specific subdirectory?
Pass the path: git clean -fd ./dist.

Stop memorizing — build it interactively

Try clean commands in the Git Builder

Full reference: Git Cheat Sheet