Git Clean Has The Power To Undo All Untracked Changes To Your Repository

TopicSource
🖥️ Techgit reset --hard HEAD leaves untracked files behind - Stack Overflow

To reset your Git repository and remove untracked files, you can use the git clean command.

Here’s how:

  1. First, you can use git clean -n to perform a “dry run” and see which files would be removed1.
git clean -n
  1. If you agree with the files to be removed, you can use git clean -f to remove untracked files1.
git clean -f
  1. If you want to also remove untracked directories, you can use git clean -fd12.
git clean -fd
  1. If you want to remove ignored files as well, you can use git clean -fdx12.
git clean -fdx

Please be careful when using these commands as they will permanently delete the untracked and/or ignored files.


  1. Git revert can help you undoing a specific commit