git remove all untracked files and directories
Quick Answer
# Preview what would be deleted (dry run — safe to run first)
git clean -nfd
# Delete untracked files and directories
git clean -fd
When to use this
You have build artifacts, generated files, or editor temp files cluttering your working directory that are not in .gitignore.
Other causes & fixes
Flag reference
git clean -f # delete untracked files only
git clean -fd # delete untracked files AND directories
git clean -fdx # also delete files ignored by .gitignore (e.g. node_modules)
git clean -fdi # interactive mode — confirm each deletion
Clean only a specific subdirectory
git clean -fd src/
Related