Forrest logo
back to the git tool

git-clean:tldr:a0972

git-clean: Delete untracked files, including ignored files in `.gitignore` and `.git/info/exclude`.
$ git clean -x
try on your machine

The command "git clean -x" is used in Git to remove untracked files and directories from the working tree.

Here's what each part of the command means:

  • "git clean": This is the main command used for cleaning up the working directory.
  • "-x": This is an option that can be used with "git clean" to remove even ignored files. By default, "git clean" removes only untracked files that are not ignored.

When you run "git clean -x" in your Git repository, it will delete all untracked files and directories, including those that are ignored by Git. This can be helpful when you want to get rid of any unnecessary files that are not being tracked or version-controlled by Git.

However, before running the command, it is important to double-check and make sure that you don't have any important files in the working directory that you want to keep. The command will permanently delete these untracked files, and they cannot be recovered unless you have a backup.

To preview what files would be deleted before actually running the command, you can use the "-n" or "--dry-run" option along with "git clean", like this: "git clean -x -n". This will show you a list of files and directories that would be deleted without actually performing the deletion.

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