Git - Tutorial remove untracked files
Note: This post is over 11 years old. The information may be outdated.
If you have a bunch of untracked files and want to remove them all in one go then just do this:
$ git clean -f
Useful Options
Dry run - See what would be removed without actually deleting:
$ git clean -n
Remove untracked directories - Include directories in cleanup:
$ git clean -fd
Interactive mode - Choose which files to remove:
$ git clean -i
Force with directories - Remove both files and directories:
$ git clean -ffd
Important Notes
- Untracked files are files that Git hasn't tracked yet (not in
.gitignore, not staged, not committed) - Warning:
git cleanis destructive and cannot be undone. Always use-n(dry run) first to verify what will be deleted - Use
git cleanto clean up build artifacts, node_modules, logs, and other temporary files not tracked by Git