Skip to main content

Cleanning

When working in a Git repository, you may end up with untracked files (files that are not yet staged or committed). These can clutter your working directory, especially after switching branches or running builds that generate temporary files. Git provides the git clean command to remove untracked files and directories safely.

The git clean command is used to delete:

  • Untracked files (files that are not staged or committed).
  • Untracked directories (if explicitly specified).
  • Ignored files (if explicitly specified).

⚠️ Warning: git clean is irreversible. Once deleted, the files cannot be recovered unless backed up.

Commands

  1. git clean -n → Preview what will be deleted.
  2. git clean -f → Remove untracked files.
  3. git clean -fd → Remove untracked files and directories.
  4. git clean -fX → Remove only ignored files.
  5. git clean -fx → Remove everything untracked (including ignored files).