working-in-parallel

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Working in Parallel

并行工作

Use git worktrees to work in parallel when another agent is in the same directory.
Git worktrees let you check out multiple branches into separate directories. Each worktree has its own isolated files while sharing the same Git history and remote connections. Changes in one worktree won't affect others, so parallel agents can't interfere with each other.
当其他Agent在同一目录工作时,使用git worktrees实现并行开发。
Git worktrees允许你将多个分支检出到不同的目录中。每个worktree拥有独立的文件,但共享同一个Git历史和远程连接。一个worktree中的变更不会影响其他worktree,因此并行工作的Agent之间不会互相干扰。

IMPORTANT: Check Project Setup First

重要提示:先检查项目配置

Before running ANY commands in a new worktree, check the project's setup instructions:
  1. Read the README - Usually has install/build commands
  2. Check
    claude.md
    or
    AGENT.md
    - Agent-specific guidance if present
  3. Review your
    project
    memory block
    - Contains learned project preferences
Don't assume
npm
vs
bun
vs
pnpm
- check the project first!
在新的worktree中运行任何命令之前,请先查看项目的设置说明:
  1. 阅读README文件 - 通常包含安装/构建命令
  2. 检查
    claude.md
    AGENT.md
    - 如果存在,里面有Agent相关的指导说明
  3. 查看你的
    project
    记忆块
    - 包含已学习到的项目偏好设置
不要假设使用
npm
bun
还是
pnpm
- 一定要先检查项目配置!

Quick Start

快速开始

bash
undefined
bash
undefined

Create worktree with new branch (from main repo)

从主仓库创建带有新分支的worktree

git worktree add -b fix/my-feature ../repo-my-feature main
git worktree add -b fix/my-feature ../repo-my-feature main

Work in the worktree

进入worktree目录

cd ../repo-my-feature
cd ../repo-my-feature

CHECK PROJECT SETUP FIRST - then install dependencies

先检查项目配置 - 然后安装依赖

Read README.md or check project memory block for correct command

阅读README.md或查看project记忆块获取正确命令

bun install # Example - verify this is correct for YOUR project!
bun install # 示例 - 请确认这适用于你的项目!

Make changes, commit, push, PR

进行修改、提交、推送、创建PR

git add <files> git commit -m "fix: description" git push -u origin fix/my-feature gh pr create --title "Fix: description" --body "## Summary..."
git add <files> git commit -m "fix: description" git push -u origin fix/my-feature gh pr create --title "Fix: description" --body "## Summary..."

Clean up when done (from main repo)

完成后清理(在主仓库中执行)

git worktree remove ../repo-my-feature
undefined
git worktree remove ../repo-my-feature
undefined

Key Commands

关键命令

bash
git worktree add -b <branch> <path> main  # Create with new branch
git worktree add <path> <existing-branch>  # Use existing branch
git worktree list                          # Show all worktrees
git worktree remove <path>                 # Remove worktree
bash
git worktree add -b <branch> <path> main  # 创建带有新分支的worktree
git worktree add <path> <existing-branch>  # 使用现有分支创建worktree
git worktree list                          # 查看所有worktree
git worktree remove <path>                 # 删除worktree

When to Use

使用场景

  • Another agent is working in the current directory
  • Long-running task in one session, quick fix needed in another
  • User wants to continue development while an agent works on a separate feature
  • 其他Agent正在当前目录工作
  • 一个会话中有长时间运行的任务,同时需要在另一个会话中快速修复问题
  • 用户希望在Agent开发其他功能的同时继续自己的开发工作

Tips

小贴士

  • Check project setup docs before installing - README, claude.md, project memory block
  • Name directories clearly:
    ../repo-feature-auth
    ,
    ../repo-bugfix-123
  • Install dependencies using the project's package manager (check first!)
  • Push changes before removing worktrees
  • 安装依赖前先检查项目配置文档 - README、claude.md、project记忆块
  • 清晰命名目录:
    ../repo-feature-auth
    ../repo-bugfix-123
  • 使用项目指定的包管理器安装依赖(务必先确认!)
  • 删除worktree前先推送变更

Alternative: Repo Clones

替代方案:仓库克隆

Some users prefer cloning the repo multiple times (
gh repo clone owner/repo project-01
) for simpler mental model. This uses more disk space but provides complete isolation. If the user expresses confusion about worktrees or explicitly prefers clones, use that approach instead.
有些用户更喜欢多次克隆仓库(
gh repo clone owner/repo project-01
),这种方式逻辑更简单。它会占用更多磁盘空间,但能提供完全的隔离。如果用户对worktrees感到困惑,或者明确偏好克隆方式,可以使用该方案替代。