How to remove local untracked files from the current Git branch

In this article we will see how we can clean local untracked files from the current git branch, As per git official documentation command for this is git clean.

  • It’s important to see and verify which files will be deleted you can use the -n the option before you run the actual command:
git clean -n
  • Then when you verified (and you are 100% sure because it will be difficult to recover these files to recover) use the -f option:
git clean -f

Here are some more options for you to delete directories, files, ignored and non-ignored files

  • To know which files will be deleted run git clean -f
  • To remove files, run git clean -f
  • To remove directories, run git clean -f -d or git clean -fd
  • To remove ignored files, run git clean -f -X or git clean -fX
  • To remove ignored and non-ignored files, run git clean -f -x or git clean -fx