Unfuddle STACK Tips & Tricks
How do I remove untracked files from my Git repository?
Untracked files are files that Git does not know about. A simple way to delete these is using git-clean
.
Preview untracked files with git clean -n
.
# list untracked files
$ git clean -n
Would remove LICENSE
Would remove README.md
# list both files and directories
$ git clean -nd
Would remove LICENSE
Would remove README.md
Would remove script/
Would remove spec/
Use git clean -f
to permanently remove the files:
# remove untracked files
$ git clean -f
Removing LICENSE
Removing README.md
# remove both files and directories
$ git clean -fd
Removing LICENSE
Removing README.md
Removing script/
Removing spec/
Check the Full Official Documentation for more options.