I'm writing Autotools code and in the process of development, tons of files are generated.
Is there anyway to tell git to remove all files from a directory that are not part of the repository?
I'm writing Autotools code and in the process of development, tons of files are generated.
Is there anyway to tell git to remove all files from a directory that are not part of the repository?
You can use git-clean. This command will remove untracked files/directories. By default, it will only print what it would have removed, without actually removing them.
Given the -f
flag to remove the files, and the -d
flag to remove empty directories as well :
git clean -df
Also removing ignored files :
git clean -dfx
git clean
on its own will actually remove all untracked files - except when the Git configuration variable clean.requireForce is set to true. If its set to false, then -ff is needed for cleaning diretories
git clean -ix
will show you what it will clean and give you a menu of options. My favorite.