← ClaudeAtlas

repo-tidylisted

Git repository tidy-up and parallel-task base: switch back to the latest master/main, delete merged or upstream-gone branches, remove stale worktrees; `--new <task>` does tidy + create a task branch in one command and auto-creates a parallel worktree when the main checkout is busy; a SessionStart hook injects repo status when a session starts. Use before a new repository-changing task or when the user explicitly requests cleanup. Read-only audits, questions, continued tasks, and [repo-status] alone do not trigger mutations. Also use when the user says 归位, 整理仓库, 清理分支, 清理 worktree, 开新任务, repo tidy, tidy repo, clean branches.
hanzhangzzz/agent-skills-zh · ★ 1 · AI & Automation · score 67
Install: claude install-skill hanzhangzzz/agent-skills-zh
# repo-tidy 把本地仓库恢复到「默认分支与远端一致、无可安全回收的遗留分支/worktree」的基线状态。默认分支优先读取 origin/HEAD,缺少该引用时才兼容 master/main。归位发生在**下一个任务开始时**(push 完 MR 未合,任务结束时无收尾时机)。 组件(脚本就地运行于 skill 目录,不复制副本): - `scripts/repo_tidy.py` —— 核心:tidy / `--all` / `--new` - `scripts/git-repo-status.sh` —— SessionStart hook,开局注入一行 `[repo-status]`(分支/ahead-behind/脏净)。注册到 `~/.claude/settings.json` 的 `hooks.SessionStart`:`{"matcher": "*", "hooks": [{"type": "command", "command": "<skill绝对路径>/scripts/git-repo-status.sh", "timeout": 10}]}` - `tests/test_repo_tidy.sh <scratch目录>` —— 对抗测试(含双默认分支与非标准默认分支的对抗场景),改脚本后必须跑 ## 何时用 - 用户说「归位」「整理仓库」「清理分支/worktree」 - 需要修改仓库的新任务开工前;只读审计、问答、续任务不归位,`[repo-status]` 本身不触发动作 - 显式调用 do-something 时遵循该 skill 的 do/main 续做规则,不额外开普通任务分支 - 用户明确要求提交后的仓库整理 ## 执行步骤 ### 1. Dry-run 出清单 `SKILL_DIR` 指本 SKILL.md 所在目录(全局安装、项目级安装、plugin 缓存目录均适用,按实际安装位置解析,不要硬编码)。 ```bash # 单仓库(默认当前目录) python3 "$SKILL_DIR/scripts/repo_tidy.py" <repo-path> # 全部仓库(扫描 ~/Desktop/Works/code) python3 "$SKILL_DIR/scripts/repo_tidy.py" --all ``` ### 2. 确认后执行 把 dry-run 清单展示给用户;**涉及删除分支/worktree 时必须等用户确认**(用户本轮已明确说「清理」「归位」的,单仓库可直接 `--apply`)。 ```bash python3 "$SKILL_DIR/scripts/repo_tidy.py" <repo-path> --apply ``` ### 3. 开新任务(一条命令:归位 + 开分支/worktree) ```bash python3 "$SKILL_DIR/scripts/repo_tidy.py" <repo-path> --new <task> ``` - 先对该仓库执行一次归位(等价 `--apply`,安全边界相同) - 主检出空闲(在默认分支且无 tracked 改动)→ 原地 `switch -c task/<task> origin/<默认分支>` - 主检出被占用(停在进行中分支或有改动)→ 自动创建 sibling worktree `<仓库>--<task>`(基于最新 origin/<默认分支>)并输出 `cd` 路径 ——