How to remove untracked files and directories?
git clean -f -d
To remove untracked files and directories from the working directory use git clean -f -d
.
Since git clean
removes files it's recommended to start with a dry-run using parameter -n. A dry-run will show what is going to be removed without actually removing them.
The -f parameter tells git to remove the files when git clean
is used. The usage of parameter -f is required unless clean.requireForce is configured to false.
The -d parameter tells git to clean files recursively and remove directories as well.
git clean -n -d
Would remove new-directory/
Would remove new-file.txt
git clean -f -d
Removing new-directory/
Removing new-file.txt
See git clean to learn more about it.