Skip to main content

What does git clean do?

git clean removes untracked files and directories from the working tree.


What counts as untracked

  • files that are not added to Git
  • files that are not in any commit
  • temporary files, build artifacts, logs, and so on

What the command does

bash
git clean -f
  • removes untracked files
  • does not touch committed files
  • does not change history

Commonly used options

bash
git clean -n

Shows what would be removed, without removing anything (a dry run).

bash
git clean -f

Removes untracked files.

bash
git clean -fd

Removes untracked files and directories.

bash
git clean -fx

Also removes files ignored via .gitignore.


What git clean does NOT do

  • does not remove modified but tracked files
  • does not undo changes in tracked files
  • does not affect commits or history

Important

git clean permanently deletes files. It is recommended to first use:

bash
git clean -n

Key phrasing for an interview

git clean removes untracked files and directories from the working tree. The command does not change the commit history, but it can lead to data loss, so it is usually used with a preview first.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.