git cleanRemoves untracked files from your working directory. Unlike git reset, it doesn't touch tracked files — only files Git isn't tracking.
Dry run (-n)Shows what would be removed without actually deleting anything. Always run git clean -n first to avoid accidental data loss.
-f vs -fdgit clean -f only removes untracked files at the root level. Add -d to also remove untracked directories (and all files inside them).
-fX (remove ignored)git clean -fX removes only files that match .gitignore rules — build artifacts, compiled files, etc. — while leaving your untracked personal files alone.
Check the repository status
Run git status. debug.log, temp.txt, and the build/ directory are untracked clutter left over from running and building your project. Notice .gitignore is also untracked — we'll commit it later so Git remembers which files to ignore.
● Check the repository status
○ Dry run with git clean -n
○ Remove root-level clutter with git clean -f
○ Remove the build directory with git clean -fd
○ Clean only ignored files with git clean -fX
○ Final check with git status
Terminal
📘 Starting tutorial: Git Clean
Remove untracked files and build artifacts from your working directory