Skip to content
Latchkey

git clean: Usage, Options & Common CI Errors

git clean deletes untracked files so your working tree matches the repo exactly.

Clean is great for resetting a dirty runner workspace, but it permanently deletes files, so always dry-run first.

What it does

git clean removes files that Git is not tracking. It does not touch tracked files (use restore/reset for those) and requires -f to actually delete anything.

Common usage

Terminal
git clean -n                  # dry run: list what would be deleted
git clean -fd                 # delete untracked files + dirs
git clean -fdx                # also delete ignored files
git clean -fd -e .env         # but keep .env

Options

FlagWhat it does
-n / --dry-runShow what would be removed
-f / --forceActually delete (required)
-dAlso remove untracked directories
-xAlso remove ignored files
-e <pattern>Exclude paths from cleaning

Common errors in CI

fatal: clean.requireForce defaults to true; refusing to clean without -i, -n or -f - clean will not run without one of those. Beware -x on runners: it deletes .gitignored caches (node_modules, build output), which can wipe a restored cache.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →