Git – Remove untracked files matching a pattern
$ git clean [-n] -f <path>...
$ git clean -n -f *.json
to remove all untracked json files.
--dry-run before running the command.
git clean– Remove untracked files from the working tree.
--dry-run– Show the list of files that would be removed without actually removing.
--force– If the Git configuration variable
clean.requireForceis not set to
git cleanwill refuse to delete files or directories unless given
-i. Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second
-d– Normally, when no
git cleanwill not recurse into untracked directories to avoid removing too much. Specify
-dto have it recurse into such directories as well. If any paths are specified,
-dis irrelevant; all untracked files matching the specified paths (with exceptions for nested git directories mentioned under
--force) will be removed.
--interactive– Show what would be done and clean files interactively.
--exclude– Use the given exclude pattern in addition to the standard ignore rules.