There's more...

If we need to remove the ignored files, we can of course use git clean to do this; instead of the dry-run option, we pass the force option, -f:

$ git clean -Xfd
Removing bin/foobar
Removing test.test
Removing test.txt.bak

To remove all the untracked files and not just the ignored files, use git clean -xfd. The lowercase x means we don't use the ignore rules, we just remove everything that is not tracked by Git.

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.