How to remove local untracked files from the current Git branch (source)
- To see what files will be removed, use
git clean -n - To remove files, run
git clean -f - To remove files and directories, run
git clean -f -dorgit clean -fd - To remove ignored files, run
git clean -f -Xorgit clean -fX - To remove ignored and non-ignored files, run
git clean -f -xorgit clean -fx
(Note the case difference on the -x and -X for the two latter commands.)
To see other options, use:
git clean -h(short version of help text)git clean --help(longer version of help text)
CAUTION! When using the commands the remove ignored files, you may end up removing files such as the following that are typically in the .gitignore and contain your application configuration secrets:
temp-configuration.txtsecrets-localhost.propertiessecrets-heroku.propertiesjavascript/.env.local
So proceed with caution.