Progress:
TIER 1 · MODULE 26· Basics

git clean

There is no undo. Use -n first. Always.

🎯 What & why

Delete untracked files from the working tree. There is no undo — the files were never in the index, never in the object DB.

🧠 Mental model

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.

🛠️ Synopsis

git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...

🎚️ Switches & options

FlagWhat it does
-n, --dry-runShow what would be deleted, do nothing. Always run this first.
-f, --forceRequired to actually delete (unless clean.requireForce=false).
-dRecurse into untracked directories.
-iInteractive — prompt before each.
-xAlso delete files that match .gitignore (build artifacts, dependencies).
-XOnly delete .gitignore-matched files; keep other untracked.

💡 Use cases

🧪 Examples

Always start with dry-run.
$ git clean -nfd
Now do it for real.
$ git clean -fd
Nuke everything untracked, including ignored.
$ git clean -fdx   # ⚠️ destructive
Interactive — pick what to delete.
$ git clean -id

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.