Git Clean
In one line
git clean removes untracked files and directories from the working directory, complementing git reset for tracked files.
In simple words
git clean deletes untracked files (and optionally directories) from your working tree. Where git reset moves tracked files, git clean removes the files Git is not tracking — build artifacts, editor temp files, things you created but never git add-ed. Together, reset + clean can return a repo to a pristine state.
By default git clean does nothing (a safety measure). You add -f to force, -d to also remove untracked directories, and -x to also remove ignored files (those matching .gitignore). -n (dry run) shows what would be deleted without doing it — always run this first.
This is useful for build resets (remove all generated files before a clean build), for recovering from a messy state, and in CI to ensure no stray files affect the build. Be careful: clean permanently deletes files, they are not in Git and cannot be recovered.
Example
# See what would be removed (always dry-run first!)
git clean -nfd
# Would remove:
# build/
# debug.log
# temp.txt
# Remove untracked files and directories
git clean -fd
# Also remove ignored files (build artifacts in .gitignore)
git clean -fdx
# Remove only ignored files
git clean -fdX-n dry-run, -f force, -d include directories, -x include ignored files, -X only ignored files. Always dry-run first.
Related terms
Related Resources
Related Lessons
- Git Cleanup
Learn git clean.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.