git clean
Removes untracked files from the working directory.
Syntax
git clean [<options>]
Options
- -n / --dry-run: Shows what would be removed without actually deleting
- -f / --force: Required to actually delete files (safety measure)
- -d: Also removes untracked directories
- -x: Also removes files ignored by .gitignore
- -X: Removes only files ignored by .gitignore
- -i / --interactive: Shows what would be removed and allows selection
Example
git clean -n git clean -fd git clean -fxd
Tip
Always run with -n (dry run) first to see what will be deleted.