git clean

The use of .gitignore files with git makes the maintenance of a tidy repository a much easier experience, however it does have the side effect of hiding any built files that you may wish to clean away. For example, in a Python project, the .pyc byte code files generated can clutter up the directory, and when building software with compiled languages there are often many built object files that you may wish to discard.

That’s where the git clean command comes in handy. To remove all files not under version control, run:

git clean -xdf

or, to remove only files in .gitignore (thereby keeping any untracked files) reported by git status), run:

git clean -Xdf