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.
Aliases the pros type
Memorize the git clean concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git clean -ng clean -ngit clean -nAlways preview first — the safe version!
g cluxegit clean -fdxThe full sweep: files, dirs, ignored. Known in hushed tones.
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.
Pro tip
Make the safe default the default: `git config --global alias.accurate "clean -n"` and habitually run it before any real -fdx. One dry-run of `git clean -fdx` in a new clone reads like a horror list of everything you did NOT want to lose.