Use git clean -n to preview untracked files Git would remove. After checking the list, run git clean -f to delete those files. Add -d if you also want untracked directories included. The preview is essential: git clean deletes files, and its ignored-file options can broaden the scope.
Check what Git considers untracked
Start with git status to see the state of your working tree. git clean removes files that are not under version control; it does not discard edits to tracked files. If your goal is to revert changes to tracked files, do not use this command.
As an Amazon Associate I earn from qualifying purchases.
The Git project describes git clean as recursively removing files that are not under version control, starting from the current directory. Its official manual is updated through Git 2.56.0: git-clean.
Preview before deleting
Run a dry run first:
git clean -n
The -n option, also written --dry-run, shows what Git would remove without deleting anything. This preview does not include untracked directories by default. To preview those too, run:
#1 Best Overall
git clean -n -d
Read the output and confirm every listed path is safe to discard. If it includes work you want to keep, stop and narrow the scope before running a deletion command.
Remove the files shown in the preview
Once the dry run shows the intended files, run the matching command with -f:
Rank #2
git clean -f
To remove untracked directories as well, include -d:
git clean -f -d
Git normally requires the force option before deleting anything. If clean.requireForce is disabled in your configuration, that safeguard may not apply; check the preview regardless. A second -f permits Git to modify an untracked nested Git repository, such as another repository inside a directory. Use that only when you specifically intend to remove that nested repository.
Choose a narrower or interactive cleanup
Limit cleanup to a path
When only particular paths should be cleaned, supply a pathspec, for example:
git clean -n -- path/to/folder
If the preview is correct, run the same pathspec with force:
git clean -f -- path/to/folder
A pathspec scopes the affected paths; with a pathspec, -d is irrelevant. Always preview again with the same pathspec and cleanup options you plan to use for deletion.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteSelect candidates interactively
Use interactive mode when you want to choose among the candidates rather than remove everything in scope:
Best Value
git clean -i
Git presents cleanup choices so you can select what to remove. Review the candidates carefully before confirming a selection.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Understand ignored files: -x and -X
By default, git clean respects Git’s ignore rules. The two options that change this behavior have different scopes:
-xdisables the standard ignore rules, so ignored files as well as other untracked files may be removed. Command-line exclusions supplied with-eare still retained.-Xremoves only files ignored by Git, leaving other untracked files alone. This can help clear ignored build output while preserving manually created untracked files.
Preview either mode before deleting. For example, inspect ignored files only with:
Free tools Windows power users keep installed
One-click scans. No signup required.
git clean -n -X
Use -x only if you intend to include ignored files in the cleanup. Those files may contain local settings, generated output, or other work you have not committed.
Git clean options at a glance
| Option | Effect |
|---|---|
-n / --dry-run |
Show what would be removed without deleting it. |
-i / --interactive |
Present candidates and let you make cleanup choices. |
-d |
Include untracked directories when no pathspec is supplied. |
-f / --force |
Permit deletion when the force requirement is enabled; normally required for actual cleanup. |
-x |
Disable standard ignore rules so ignored and other untracked files may be removed; command-line -e exclusions remain. |
-X |
Remove only files ignored by Git. |
-e <pattern> |
Add an exclusion pattern to preserve matching paths during cleanup. |
<pathspec> |
Limit cleanup to matching paths; -d is then irrelevant. |
Second -f |
Allow modification of an untracked nested Git repository. |
These behaviors are documented in the official Git clean manual.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




