git-clean
git clean อย่างปลอดภัย — dry-run ก่อนเสมอ, ลบ untracked/ignored files ตาม scope
SKILL.mdgit-clean/SKILL.md
GitHubGoal
Remove untracked files with git clean — always dry-run first, because untracked files are not in git history and cannot be recovered
Scope
git clean -fd(untracked files+dirs),-fdx(including ignored — build output),-ndry-run- fills the gap of
/git-restore, which does not touch untracked files - general build artifact/dependency cache cleanup →
/cleanup-files-in-project
Execute
1. Preview (Always Dry-Run)
Goal: see every file that will be gone before actually deleting
git clean -nd # preview untracked files+dirs
git clean -ndx # preview including ignored files (node_modules, dist, ...)
git clean -nd <path> # preview a specific path only
-n(dry-run) every time, no exceptions- review the list — untracked files may be work not yet added (
.env.local, scratch files, new work) - files you might want →
git add -N(intent-to-add protects from clean) or/git-stash -u
2. Choose Scope
Goal: delete only what is intended
| Flag | Removes what |
|---|---|
-fd |
untracked files + dirs |
-fdx |
+ ignored files (build output, ignored .env* — careful) |
-fdX |
only ignored files (clear build artifacts while keeping untracked sources) |
<path> |
restricted to a path |
- start from the narrowest scope (
<path>or-fdX) before widening -fdxis the riskiest — ignored files include.env, local config, and hard-to-recreate IDE files
3. Execute And Verify
Goal: deletion matches the preview and the repo still works
- run clean at the chosen scope
git statusverify — tracked files are never touched (clean only touches untracked/ignored)- if ignored deps were deleted → reinstall/rebuild (
bun installetc.)
Rules
git cleanhas no undo — untracked files are not in the object store, they are gone permanently- always
-ndry-run first + show the user the file list to delete when the scope is wide - second-thought the
-xflag — it swallows ignored files including local secrets/config - tracked changes are unrelated to clean — use
/git-restoreto discard or/git-stash - Use /ask-me if needed
Expected Outcome
- untracked/ignored files removed per the previewed scope
- no important files lost by accident