Remove untracked git files

To remove all untracked files & directories, you can use these commands:

  1. first list what is going to be removed, and verify what will be deleted:
    git clean -fdx -n
  2. after you verified what is going to be deleted, remove the -n flag:
    git clean -fdx

the flags we use here are:

  • -f force, in case your git config has the clean.requireForce variable
  • -x to remove both ignored & non ignored files
  • -d remove untracked directories as well
  • -n don’t remove anything, just list what will be deleted

Leave a Reply

Your email address will not be published. Required fields are marked *