How to Remove Untracked Files in Git (git clean)

git clean deletes files that are untracked by Git — files never added or committed — from your working directory.

Published September 28, 2026

git clean deletes untracked files and directories from your working tree. Because it cannot be undone, always preview with -n first.

How it works

It only affects files Git is not tracking. Ignored files are kept unless you add -x.

-f is required to actually delete, as a safety measure.

Try it

git clean -n
Would remove temp.log
git clean -f
Removing temp.log

Practical examples

Preview

git clean -n

Remove files and directories

git clean -fd

Include ignored files (builds)

git clean -fdx

Interactive

git clean -i

Common mistakes

  • Skipping the dry run and deleting needed files.
  • Using -x and wiping .env or local config.
  • Expecting it to revert tracked changes (use git restore).

Key takeaways

  • Removes untracked files only.
  • Always preview with -n.
  • -x also removes ignored files.

FAQ

Can I recover cleaned files?

Not through Git, they were never committed.

clean vs restore?

clean removes untracked; restore discards changes to tracked files.

More Git articles