How to clean ignored files in Git

Cleaning ignored files in Git removes build artifacts, temporary files, and other content specified in .gitignore that may accumulate in your working directory. As the creator of CoreUI with extensive Git experience across numerous projects, I regularly clean ignored files to free up disk space and maintain repository hygiene. The most thorough approach uses git clean with the -x flag to remove both untracked and ignored files completely. This method provides deep cleanup while respecting Git’s file tracking configuration.

Use git clean -fdx to remove untracked files, directories, and files ignored by .gitignore.

git clean -fdx

This command removes untracked files (-f for force), directories (-d), and ignored files (-x for ignored). The -x flag tells Git to also delete files that would normally be ignored according to .gitignore rules, such as node_modules, build directories, or temporary files. This provides the most thorough cleanup of your working directory, removing everything that’s not tracked by Git.

Best Practice Note:

This is the deep cleanup command we use in CoreUI development before major deployments or when switching between different development environments. Use git clean -nfdx first to preview all files that will be deleted, especially since this removes dependency folders that may take time to reinstall.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
Dealing with Sass Deprecation Warnings in Angular 19
Dealing with Sass Deprecation Warnings in Angular 19

How to change opacity on hover in CSS
How to change opacity on hover in CSS

How to limit items in a .map loop in JavaScript
How to limit items in a .map loop in JavaScript

How to replace all occurrences of a string in JavaScript?
How to replace all occurrences of a string in JavaScript?

Answers by CoreUI Core Team