ce-worktree

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Worktree Creation

创建Worktree

Create a worktree under
.worktrees/<branch>
with branch-specific setup that
git worktree add
alone does not handle:
  • Copies
    .env
    ,
    .env.local
    ,
    .env.test
    , etc. from the main repo (skips
    .env.example
    )
  • Trusts
    mise
    /
    direnv
    configs, with branch-aware safety rules so review branches do not auto-grant trust to untrusted
    .envrc
    content
  • Adds
    .worktrees
    to
    .gitignore
    if not already ignored
  • Does not modify the main repo checkout —
    from-branch
    is fetched, not checked out
.worktrees/<branch>
下创建一个Worktree,包含
git worktree add
单独无法处理的分支专属配置:
  • 从主仓库复制
    .env
    .env.local
    .env.test
    等文件(跳过
    .env.example
  • 信任
    mise
    /
    direnv
    配置,同时带有分支感知的安全规则,确保评审分支不会自动信任未受信任的
    .envrc
    内容
  • 如果
    .worktrees
    尚未被忽略,则将其添加到
    .gitignore
  • 不会修改主仓库的检出内容——仅拉取
    from-branch
    ,不会检出该分支

Creating a worktree

创建Worktree

bash
bash scripts/worktree-manager.sh create <branch-name> [from-branch]
Defaults:
  • from-branch
    defaults to origin's default branch (or
    main
    if that cannot be resolved)
  • The new branch is created at
    origin/<from-branch>
    (or the local ref if the remote is unavailable)
Examples:
bash
bash scripts/worktree-manager.sh create feat/login
bash scripts/worktree-manager.sh create fix/email-validation develop
After creation, switch to the worktree with
cd .worktrees/<branch-name>
.
bash
bash scripts/worktree-manager.sh create <branch-name> [from-branch]
默认规则:
  • from-branch
    默认使用origin的默认分支(如果无法解析则使用
    main
  • 新分支基于
    origin/<from-branch>
    创建(如果远程不可用则基于本地引用)
示例:
bash
bash scripts/worktree-manager.sh create feat/login
bash scripts/worktree-manager.sh create fix/email-validation develop
创建完成后,使用
cd .worktrees/<branch-name>
切换到该Worktree。

Other worktree operations

其他Worktree操作

Use
git
directly — no wrapper is needed and none is provided:
bash
git worktree list                          # list worktrees
git worktree remove .worktrees/<branch>    # remove a worktree
cd .worktrees/<branch>                     # switch to a worktree
cd "$(git rev-parse --show-toplevel)"      # return to main checkout
To copy
.env*
files into an existing worktree created without them, run this from the main repo (not from inside the worktree, since branch names often contain slashes like
feat/login
):
bash
cp .env* .worktrees/<branch>/
直接使用
git
命令即可——无需也未提供封装脚本:
bash
git worktree list                          # 列出所有Worktree
git worktree remove .worktrees/<branch>    # 删除一个Worktree
cd .worktrees/<branch>                     # 切换到某个Worktree
cd "$(git rev-parse --show-toplevel)"      # 返回主仓库检出目录
如果要将
.env*
文件复制到未包含这些文件的现有Worktree中,请从主仓库运行以下命令(不要在Worktree内部运行,因为分支名称通常包含斜杠,如
feat/login
):
bash
cp .env* .worktrees/<branch>/

Dev tool trust behavior

开发工具信任行为

When mise or direnv configs are present, the script attempts to trust them so hooks and scripts do not block on interactive prompts. Trust is baseline-checked against a reference branch:
  • Trusted base branches (
    main
    ,
    develop
    ,
    dev
    ,
    trunk
    ,
    staging
    ,
    release/*
    ): the new worktree's configs are compared against that branch; unchanged configs are auto-trusted.
    direnv allow
    is permitted.
  • Other branches (feature branches, PR review branches): configs are compared against the default branch;
    direnv allow
    is skipped regardless, because
    .envrc
    can source files that direnv does not validate.
Modified configs are never auto-trusted. The script prints the manual trust command to run after review.
当存在mise或direnv配置时,脚本会尝试信任这些配置,以便钩子和脚本不会因交互式提示而阻塞。信任会基于参考分支进行基线检查:
  • 受信任的基础分支
    main
    develop
    dev
    trunk
    staging
    release/*
    ):将新Worktree的配置与该分支进行比较;未更改的配置会被自动信任,允许执行
    direnv allow
  • 其他分支(功能分支、PR评审分支):将配置与默认分支进行比较;无论如何都会跳过
    direnv allow
    ,因为
    .envrc
    可能会加载direnv未验证的文件。
修改后的配置永远不会被自动信任。脚本会输出审核后需要运行的手动信任命令。

When to create a worktree

何时创建Worktree

Create a worktree when:
  • Reviewing a PR while keeping the main checkout free for other work
  • Running multiple features in parallel without branch-switching overhead
  • Keeping the default branch free of in-progress state
Do not create a worktree for single-task work that can happen on a branch in the main checkout.
在以下场景创建Worktree:
  • 评审PR的同时,保持主检出内容可用于其他工作
  • 并行开发多个功能,避免分支切换的开销
  • 保持默认分支不包含未完成的工作状态
对于可在主检出的分支上完成的单任务工作,无需创建Worktree。

Integration

集成

ce-work
and
ce-code-review
offer this skill as an option. When the user selects "worktree" in those flows, invoke
bash scripts/worktree-manager.sh create <branch>
with a meaningful branch name derived from the work description (e.g.,
feat/crowd-sniff
,
fix/email-validation
). Avoid auto-generated names like
worktree-jolly-beaming-raven
that obscure the work.
ce-work
ce-code-review
提供了使用该功能的选项。当用户在这些流程中选择“worktree”时,会调用
bash scripts/worktree-manager.sh create <branch>
,并根据工作描述生成有意义的分支名称(如
feat/crowd-sniff
fix/email-validation
)。避免使用
worktree-jolly-beaming-raven
这类自动生成的名称,因为它们会掩盖工作内容。

Troubleshooting

故障排查

"Worktree already exists": the path is already in use. Either switch to it (
cd .worktrees/<branch>
) or remove it (
git worktree remove .worktrees/<branch>
) before recreating.
"Cannot remove worktree: it is the current worktree":
cd
out of the worktree first, then
git worktree remove
.
Dev tool trust was skipped: the script prints the manual command. Review the config diff (
git diff <base-ref> -- .envrc
), then run the printed command from the worktree directory.
"Worktree已存在":该路径已被占用。可以切换到该Worktree(
cd .worktrees/<branch>
),或者先删除它(
git worktree remove .worktrees/<branch>
)再重新创建。
"无法删除Worktree:它是当前Worktree":先退出该Worktree(
cd
到其他目录),再执行
git worktree remove
开发工具信任被跳过:脚本会输出手动命令。查看配置差异(
git diff <base-ref> -- .envrc
),然后从Worktree目录运行输出的命令。