There is no undo. Use -n first. Always.
Delete untracked files from the working tree. There is no undo — the files were never in the index, never in the object DB.
Clean walks the working tree, finds files Git doesn't know about (subject to .gitignore), and deletes them. Without -f, modern Git refuses to do anything (safety). With -d, it deletes untracked directories. With -x, it ignores .gitignore and deletes truly everything untracked.
git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...| Flag | What it does |
|---|---|
-n, --dry-run | Show what would be deleted, do nothing. Always run this first. |
-f, --force | Required to actually delete (unless clean.requireForce=false). |
-d | Recurse into untracked directories. |
-i | Interactive — prompt before each. |
-x | Also delete files that match .gitignore (build artifacts, dependencies). |
-X | Only delete .gitignore-matched files; keep other untracked. |
git reset --hard).$ git clean -nfd$ git clean -fd$ git clean -fdx # ⚠️ destructive$ git clean -idgit clean -nfd. Run it first. Always.make clean target that wraps git clean -fdX so you delete only gitignored stuff.-x like rm -rf. Don't keystroke it absentmindedly.-x deletes everything .gitignore covers, which usually includes uncommitted secrets, env files, or build artifacts you wanted.git clean does not delete tracked files. For that, you need git rm or reset --hard.Hit each option, then Check answers. Score is recorded; Next is always open.