git-clean
Remove untracked files from working tree
TLDR
Preview files to remove
SYNOPSIS
git clean [options] [path]
DESCRIPTION
git clean removes untracked files from the working tree. It cleans up generated files, build artifacts, and other files not tracked by git.
The command requires -f to actually delete files, preventing accidental data loss. Dry run mode (-n) shows what would be removed without deleting anything. Options control whether ignored files (-x/-X) and directories (-d) are included.
Combined with git reset --hard, git clean provides a complete way to return the working tree to a pristine state matching the last commit. Always preview with -n first, as deleted untracked files cannot be recovered through Git.
PARAMETERS
-n, --dry-run
Show what would be removed.-f, --force
Actually remove files.-d
Remove untracked directories.-x
Remove ignored files too.-X
Remove only ignored files.-i, --interactive
Interactive mode.-e PATTERN
Exclude pattern.--help
Display help information.
CAVEATS
Deleted files cannot be recovered. Always use -n first. Force required to prevent accidents.
HISTORY
git clean is a core Git command for maintaining clean working directories, particularly useful for build cleanup and fresh starts.
SEE ALSO
git-status(1), git-reset(1), gitignore(5)
