vqwpgg
Last Updated: February 25, 2016
·
1.365K
· dmichaelavila
Photo

Removing untracked files from a git repo

git

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.

Say Thanks
Respond

4 Responses
Add your response

12100
7dedb03c52d9b14738f844c799b2dbc4

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 ·
12101
Photo

@fernandoperigolo thanks for that note!

over 1 year ago ·
12143
C360 2014 12 05 11 14 32 972

Nice tip

over 1 year ago ·
12217
89bf0c86f9854c8e7224b7ccd736b564

worth noting. Thanks

over 1 year ago ·