How to remove ignored files?
git clean -f -X
To remove files ignored by git use git clean -f -X
.
Since git clean
removes files it's recommended to start with a dry-run using parameter -n. A dry-run will show what is going to be removed without actually removing them.
The -f parameter tells git to remove the files when git clean
is used. The usage of parameter -f is required unless clean.requireForce is configured to false.
The -X parameter tells git to remove ignored files only, but keep the untracked ones.
Git clean -f -X
won't remove ignored directories. Add parameter -d to remove directories as well.
cat .gitignore
ignoredFile.txt
ignoredDir/
git clean -n -X
Would remove ignoredFile.txt
git clean -f -X
Removing ignoredFile.txt
See git clean to learn more about it.