Preview and Clean Untracked Files

List or delete untracked and ignored files in a working tree.

macOSFilesgitcliLow risk
Run git clean -nd to preview what would be removed before committing to a clean.

01Command

Command
$ git clean -nd

02What it does

Build scripts leave generated files that git ignores; git clean removes them without touching tracked files. The -n dry run and -X flag make it safe to preview exactly what will go, which is faster and more precise than hunting leftovers in a file manager.

03Risk

RiskLow risk
RequirementsGit 2.20+ (install with Homebrew or Xcode Command Line Tools)
CompatibilitymacOS with Git installed (Homebrew or Xcode Command Line Tools)
!Warning: Without -n, git clean -fd permanently deletes untracked files and cannot be undone by git.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • git-clean documentation
    Git · vendor-doc · 2026-09-20
    Evidence: Documents git clean, including the -n dry run and -X ignored-only options.

Last verified: 2026-10-13 · Category: Developer

06Related solutions