git clean
intermediateDelete untracked, unignored files from your working tree.
git cleanWhat it does
git clean removes files that Git has never tracked and that .gitignore does not protect: build artifacts, stray logs, unneeded temp files. Because deletion is permanent, every sane workflow pairs git clean with a dry-run first (-n).
git clean finds and permanently deletes untracked files
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Stray files everywhere
Untracked files and build junk litter your worktree. First, preview what clean would remove.
git clean -n??? = untracked · clean only touches these
Under the hood
It walks the worktree, not the repo
Clean scans the working tree for paths with no index entry, then removes them. It writes the *deletion* as real file removal — there is no undo, no reflog, no staging. That's why -n (dry run) is the reflex.
-f is a guard, -d descends into dirs, -x adds ignored
By default clean won't touch directories (needs -d) and never touches ignored files (-n/-f only shown unignored). -x widens it to INCLUDING ignored files — the true remove-everything button.
Clean + reset = the nuclear combo
`git reset --hard` handles tracked changes; `git clean -fdx` handles everything untracked. Together they produce a pristine worktree — a real project-whisperer move before a fresh branch.
Command anatomy
-nDry run: list what would be deleted, delete nothing.
-dRemove untracked directories as well as files.
-xAlso remove ignored files (the full nuclear option).
-fActually do the deleting.
When to reach for it
Clearing out build artifacts and node_modules before zipping a folder.
You deleted a file but git status still shows it? clean -f nukes the leftover copies from ignored dirs.
The pristine-worktree reset combo before starting fresh work.
Practice
A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.
Open practice playground