How can I preview what Git clean would remove before deleting untracked files?
Quick answer
Use git clean -n to preview what Git would remove without removing anything. If you also want the preview to include untracked directories, use git clean -nd. Review the listed paths carefully before considering cleanup: options such as -x and -X change whether ignored files are included, and a pathspec can limit the scope. A preview applies to its options, exclusions, and pathspec, so match those to the cleanup you are considering. [S1]
The question, the details, the next step.
A practical checklist
Choose whether untracked directories belong in the intended scope.
Use
-nfor a non-removing preview; add-dif previewing untracked directories.Check whether
-xor-Xchanges the treatment of ignored files.Review exclusions and any pathspec against the scope you intend.
Inspect every listed path and preserve anything you may still need.
Stop if an item is unfamiliar, unexpected, or unclear.
A few more useful answers
Does `git clean -n` delete anything?
No. The -n/--dry-run option reports what would be removed without removing anything. [S1]
Will a preview without `-d` show untracked directories?
Do not assume it will. Git clean can recurse into untracked directories with -d, so include that option when directories are part of the scope you want to preview. [S1]
Does a preview cover ignored files automatically?
The options matter: -x includes ignored files, and -X selects ignored files only. Review a preview that uses the same intended options, exclusions, and pathspec as the scope you are considering. [S1]
Sources
References used for this guide.
- [S1] Git - git-clean Documentation git-scm.com · Checked
