在 Manus 中运行任何 Skill
一键导入
一键导入
一键在 Manus 中运行任何 Skill
开始使用worktree
星标1
分支0
更新时间2026年5月6日 11:01
Git Worktree 工作流 - PR Review、并行开发、完整开发生命周期
安装
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SKILL.md
readonly菜单
Git Worktree 工作流 - PR Review、并行开发、完整开发生命周期
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
分析 Python 项目的代码品位 — 6 维度评分(极简度/一致性/可读性/防御性/工程化/Agent Engineering),输出诊断 + 处方 + SVG 雷达图报告
Awwwards 设计灵感侦察 — 按奖项/分类/技术栈/UI元素/配色采集前端设计参考
行为驱动开发(BDD)流程助手
Python 代码冗余检测清单
活文档维护
优雅编码与重构规范
| name | worktree |
| description | Git Worktree 工作流 - PR Review、并行开发、完整开发生命周期 |
| user-invocable | true |
| version | 0.0.1 |
| tags | ["git","worktree","github","workflow","parallel"] |
| dependencies | {"git":"2.19+","gh":"any"} |
不切换分支,并行处理多个任务
场景: 收到 PR 通知,需要本地审查代码
# 方式 A: 使用 gh(推荐)
gh pr checkout 123 --branch ../pr-123
# 方式 B: 手动创建
git worktree add ../pr-123 origin/pr/123
cd ../pr-123
npm install # 或依赖安装命令
npm test # 或 pytest, make test 等
# 查看变更
git log main..HEAD
# 使用 gh 查看文件变更
gh pr diff 123
# 在主仓库目录执行
cd -
gh pr review 123 --approve # 批准
# 或
gh pr review 123 --comment -m "建议..." # 评论
git worktree remove ../pr-123
场景: 同时负责 feature-A、feature-B、feature-C,需要在不同上下文间切换
# 主仓库在 /project
cd /project
# 创建 feature-A
git worktree add -b feature/A ../feature-A main
# 创建 feature-B
git worktree add -b feature/B ../feature-B main
# 创建 feature-C
git worktree add -b feature/C ../feature-C main
git worktree list
# 输出示例:
# /project main [主工作树]
# /project/../feature-A feature/A [附属]
# /project/../feature-B feature/B [附属]
# /project/../feature-C feature/C [附属]
# 在 feature-A 工作
cd ../feature-A
# ... 开发、测试、提交 ...
# 切换到 feature-B(无需 stash 或 commit)
cd ../feature-B
# ... 开发、测试、提交 ...
# 在 feature-A
cd ../feature-A
git push origin feature/A
gh pr create --title "Feature A" --body "实现..."
# 在 feature-B
cd ../feature-B
git push origin feature/B
gh pr create --title "Feature B" --body "实现..."
# feature-A 合并后
git worktree remove ../feature-A
git branch -d feature/A
场景: 完整的开发生命周期,从 Issue 到合并
# 获取 issue 信息
gh issue view 456 --json title
# 创建分支及 worktree
git worktree add -b "fix/issue-456-bug-fix" ../fix-456 main
cd ../fix-456
# 开发工作(可结合 /tdd)
# ... 编写代码、测试 ...
# 提交
git add .
git commit -m "fix: resolve issue-456"
git push origin fix/issue-456-bug-fix
# 关联 issue 创建 PR
gh pr create --title "Fix: issue-456" --body "Closes #456"
此时进入 工作流 1 (PR Review) 的反向视角:
../fix-456 修改# PR 合并后
cd - # 回到主仓库
git worktree remove ../fix-456
git branch -d fix/issue-456-bug-fix
# 拉取最新 main
git pull
git worktree list
git worktree remove ../worktree-path
git branch -d branch-name
# 如果 worktree 目录被手动删除,运行:
git worktree prune
# 删除所有已合并分支的 worktree
for wt in $(git worktree list | grep -o '../[^ ]*' | grep -v '^..$'); do
branch=$(git worktree list | grep "$wt" | awk '{print $3}' | sed 's/[\[\]]//g')
if git branch --merged main | grep -q "$branch"; then
git worktree remove "$wt"
git branch -d "$branch"
fi
done
| 工作流 | 协同命令 |
|---|---|
| PR Review | /worktree → /gh (评论/批准) |
| 并行 Feature | /worktree + /tdd (每个 worktree 独立 TDD) |
| 完整开发 | /sdr (规格) → /worktree (开发) → /gh (PR) |
# 在 worktree 中
git pull --rebase
# 解决冲突后
git push
建议放在主仓库同级目录:
~/workspace/
├── project/ # 主仓库
├── feature-A/ # worktree
├── feature-B/ # worktree
└── pr-123/ # worktree