Forrest logo
back to the git tool

git-clean:tldr:42f67

git-clean: Delete files that are not tracked by Git.
$ git clean
try on your machine

The command "git clean" is used to remove untracked files/folders from the current working directory in a Git repository.

By default, Git keeps track of only files that are being committed or have been previously committed. However, during the development process, various temporary files, build artifacts, or other generated files may be created and left untracked by Git. These untracked files may clutter the working directory and hinder version control.

The "git clean" command allows you to clean up these untracked files and directories, providing a clean working environment. When executed, it removes all untracked files and directories from the current directory, effectively deleting them from your local repository.

It is important to note that the command only removes untracked files. Tracked files, which are already committed or have modifications, are not affected by this command. To remove tracked files, you need to use other Git commands like "git rm" or "git reset".

There are several options and parameters available with the "git clean" command. Some commonly used options include:

  • "-n" or "--dry-run": Performs a dry run, showing a list of files that would be removed without deleting them.
  • "-f" or "--force": Forces the deletion of files without prompting for confirmation.
  • "-d" or "--directories": Removes untracked directories as well.
  • "-x" or "--ignored": Removes not only untracked files and directories but also ignored files.

Overall, "git clean" is a useful command for cleaning up untracked files and directories that are cluttering your working directory. It helps to maintain a clean and organized repository.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool