new-feature

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

New Feature

新功能

Each editing task gets its own worktree and branch, created from the latest
origin/main
unless the user specifies a different base. Read-only work can use the existing checkout. Never build on
main
or reuse another task's work.
每个编辑任务都应拥有独立的 worktree 和 branch,默认基于最新的
origin/main
创建,除非用户指定了其他基础分支。只读工作可以使用现有 checkout。绝不要直接在
main
上开发,也不要复用其他任务的 work。

Check existing isolation first

先检查现有隔离状态

Inspect
git worktree list
,
git status --short
, the current branch, and the session's task assignment. If the environment already created a worktree for this task, keep its path and branch and skip steps 3 and 4. In step 5, use the actual assigned path. Do not infer isolation from the editor name or a branch prefix alone. Otherwise follow all steps.
检查
git worktree list
、
git status --short
、当前 branch 以及 session 的任务分配情况。如果环境已经为该任务创建了 worktree,请保留其路径和 branch,并跳过步骤 3 和 4。在步骤 5 中,使用实际分配的路径。不要仅凭编辑器名称或 branch 前缀判断是否已经隔离。否则,执行所有步骤。

Steps

步骤

  1. Sync:
    git fetch origin
    .
  2. Scope check: run
    gh pr list
    and skim the open PRs' changed files (
    gh pr diff <n> --name-only
    ). For shared files, read the overlapping diffs. Independent edits may proceed in your own worktree. Ask for direction only when the changes conflict in behavior, require another task's unfinished work, or ownership is unclear. Check shared checkouts for uncommitted work without changing it. On another hosting platform, use its equivalent PR/MR tools; if unavailable, report the scope-check limitation and still isolate.
  3. Name the task: lowercase-with-hyphens plus a short unique suffix, e.g.
    user-auth-0816a
    . If
    git worktree add
    fails because the name exists, pick a different name — never force or reuse.
  4. Create the worktree from the repo root:
    bash
    git worktree add <worktrees-dir>/<task-name> \
      -b <branch-prefix>/<task-name> origin/main
    Use a directory outside the checkout, or a gitignored directory inside it, so worktrees cannot be committed by accident. Use a consistent branch prefix (e.g.
    agent/
    ). Follow the repo's conventions if it defines them.
  5. Enter and verify:
    bash
    cd <worktrees-dir>/<task-name>
    git branch --show-current   # must print your new branch, not main
    Confirm the required runtime version. Install dependencies inside the worktree when needed for the task's checks. Documentation-only work does not require installing an unrelated application toolchain.
  1. 同步:执行
    git fetch origin
    。
  2. 范围检查:运行
    gh pr list
    ,并快速浏览已打开 PR 的变更文件(
    gh pr diff <n> --name-only
    )。对于共享文件,读取重叠的 diff。互不影响的编辑可以在自己的 worktree 中继续进行。仅当变更在行为上存在冲突、依赖另一个任务尚未完成的工作,或文件所有权不明确时,才需要请求指示。检查共享 checkout 中是否存在未提交的工作,但不要修改它。在其他托管平台上,使用其等效的 PR/MR 工具;如果无法使用,则报告范围检查的局限性,但仍要执行隔离。
  3. 为任务命名:使用小写字母和连字符,并添加简短的唯一后缀,例如
    user-auth-0816a
    。如果
    git worktree add
    因名称已存在而失败,请选择一个不同的名称——绝不要强制使用或复用已有名称。
  4. 从仓库根目录创建 worktree:
    bash
    git worktree add <worktrees-dir>/<task-name> \
      -b <branch-prefix>/<task-name> origin/main
    使用 checkout 之外的目录,或使用 checkout 内部一个被 Git 忽略的目录,防止 worktree 被意外提交。使用统一的 branch 前缀(例如
    agent/
    )。如果仓库定义了相关规范,则遵循仓库规范。
  5. 进入并验证:
    bash
    cd <worktrees-dir>/<task-name>
    git branch --show-current   # must print your new branch, not main
    确认所需的 runtime 版本。任务需要执行检查时,在 worktree 内安装依赖。仅涉及文档的工作不需要安装无关的应用工具链。

Remember

注意事项

  • Worktrees do not isolate dev-server ports or shared databases. Tracked dependency lockfiles are separate in each worktree. Confirm a port answers your process (
    lsof -i :<port>
    ) before trusting what it serves, and resolve lockfile conflicts by regenerating, never by hand-merging.
  • Keep the worktree until the PR is merged or closed. Cleanup after merge:
    bash
    git worktree remove <worktrees-dir>/<task-name>
    git branch -D <branch-prefix>/<task-name>
    -D
    is expected: after a squash- or rebase-merge,
    -d
    refuses even though the work is merged.
  • Worktree 不会隔离 dev server 端口或共享数据库。每个 worktree 中的已跟踪依赖 lockfile 都是独立的。在信任某个端口提供的服务之前,确认该端口响应的是你的进程(
    lsof -i :<port>
    );通过重新生成来解决 lockfile 冲突,绝不要手动合并。
  • 保留 worktree,直至 PR 被合并或关闭。合并后进行清理:
    bash
    git worktree remove <worktrees-dir>/<task-name>
    git branch -D <branch-prefix>/<task-name>
    使用
    -D
    是预期行为:经过 squash merge 或 rebase merge 后,即使工作已经合并,
    -d
    仍会拒绝删除。