git-clean
Remove untracked files from working directory
TLDR
Delete untracked files
Interactively delete untracked files
Show which files would be deleted without actually deleting them
Forcefully delete untracked files
Forcefully delete untracked [d]irectories
Delete untracked files, including e[x]cluded files (files ignored in .gitignore and .git/info/exclude)
SYNOPSIS
git clean [-d] [-f | -i | -n] [-q] [-e
PARAMETERS
-d
Remove untracked directories in addition to untracked files.
If a directory is specified in
-f
Force. If the git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f, -n or -i.
-i
Interactive mode. Shows what would be done and asks interactively before removing them.
-n
Don't actually remove anything, just show what would be done. This 'dry run' mode is very useful to understand what the command will affect before actually doing it.
-q
Quiet, only report errors, but nothing else.
-e
Use exclude pattern in addition to the standard ignore rules.
Can be used multiple times.
-x
Don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but still use the ignore rules given with -e options.
-X
Remove only files ignored by Git.
This may be useful to rebuild everything from scratch, but be careful.
Clean files/directories under the specified paths. When no
DESCRIPTION
The git clean command is a powerful tool for removing untracked files from your working directory. This includes files that are not tracked by Git, such as temporary files, build artifacts, or files you've simply forgotten to add. It's essential to use git clean with caution, as it can permanently delete files. Always double-check the files that will be removed before executing the command, especially if you are using the -f (force) option without any other filters. git clean operates on the files in your working directory, leaving the files in your repository untouched. It is often used in conjunction with git reset to clean the working directory back to a known state. Remember that git clean only removes untracked files; it does not affect ignored files (specified in .gitignore), unless you specify the -x or -X options.
CAVEATS
git clean can permanently delete files. Use with caution. Always review the output of git clean -n (dry run) before executing with -f.
CONFIGURATION
The behavior of git clean can be configured using the clean.requireForce variable. If set to true (the default), git clean will refuse to run unless the -f (force), -n (dry run), or -i (interactive) option is given. Setting it to false disables this safety check.
EXIT STATUS
The command exits with 0 if successful, and non-zero if an error occurs.
SEE ALSO
git-reset(1), git-status(1), gitignore(5)