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 clean is destructive and cannot be undone. Always use -n (dry run) first to verify what will be deleted
  • Use git clean to clean up build artifacts, node_modules, logs, and other temporary files not tracked by Git
·11 years ago
11 min read
GitEdit