To remove local (untracked) files from the current Git working tree, you can use the git clean
command.
The git clean
command removes untracked files from the working tree. It does not remove ignored files, and it does not remove files that are already tracked by Git.
To remove all untracked files from the working tree, you can use the git clean
command with the -f
option:
git clean -f
This will remove all untracked files from the working tree.
If you want to remove untracked directories as well, you can use the git clean
command with the -f
and -d
options:
git clean -f -d
This will remove all untracked files and directories from the working tree.
It’s important to note that the git clean
command is a destructive operation and it cannot be undone. The untracked files and directories that are removed are deleted permanently, and they are not recoverable.
If you want to preview the files and directories that will be removed by the git clean
command, you can use the git clean
command with the -n
option, which performs a dry run and shows a list of the files and directories that would be removed.
git clean -n
This will show a list of the untracked files and directories that would be removed by the git clean
command, without actually removing them.