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.
Written by Michael
Related protips
4 Responses
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.
@fernandoperigolo thanks for that note!
Nice tip
worth noting. Thanks