Last Updated: September 04, 2018
·
2.032K
· dmichaelavila

Removing untracked files from a git repo

You can do this pretty easy with git itself.

git clean -df

You only need to pass -d if you have untracked directories. You only need to pass -f (force) if you have git configured with clean.requireForce set to true, which you likely do.

To avoid removing files unintentionally, run the following first

git clean -n

This is a 'dry run' and it tells you which files git plans on removing before it actually removes them.

If you want to be picky about how you clean up your untracked files you can use

git clean -i

This will give you options, including removing files that match a pattern.

4 Responses
Add your response

If you commit a file and after, add it in .gitignore, you can follow this steps http://stackoverflow.com/questions/1139762/gitignore-file-not-ignoring. This tip save me many times.

over 1 year ago ·

@fernandoperigolo thanks for that note!

over 1 year ago ·

Nice tip

over 1 year ago ·

worth noting. Thanks

over 1 year ago ·