ce-worktree
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWorktree Creation
创建Worktree
Create a worktree under with branch-specific setup that alone does not handle:
.worktrees/<branch>git worktree add- Copies ,
.env,.env.local, etc. from the main repo (skips.env.test).env.example - Trusts /
miseconfigs, with branch-aware safety rules so review branches do not auto-grant trust to untrusteddirenvcontent.envrc - Adds to
.worktreesif not already ignored.gitignore - Does not modify the main repo checkout — is fetched, not checked out
from-branch
在下创建一个Worktree,包含单独无法处理的分支专属配置:
.worktrees/<branch>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:
- defaults to origin's default branch (or
from-branchif that cannot be resolved)main - The new branch is created at (or the local ref if the remote is unavailable)
origin/<from-branch>
Examples:
bash
bash scripts/worktree-manager.sh create feat/login
bash scripts/worktree-manager.sh create fix/email-validation developAfter creation, switch to the worktree with .
cd .worktrees/<branch-name>bash
bash scripts/worktree-manager.sh create <branch-name> [from-branch]默认规则:
- 默认使用origin的默认分支(如果无法解析则使用
from-branch)main - 新分支基于创建(如果远程不可用则基于本地引用)
origin/<from-branch>
示例:
bash
bash scripts/worktree-manager.sh create feat/login
bash scripts/worktree-manager.sh create fix/email-validation develop创建完成后,使用切换到该Worktree。
cd .worktrees/<branch-name>Other worktree operations
其他Worktree操作
Use directly — no wrapper is needed and none is provided:
gitbash
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 checkoutTo copy 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 ):
.env*feat/loginbash
cp .env* .worktrees/<branch>/直接使用命令即可——无需也未提供封装脚本:
gitbash
git worktree list # 列出所有Worktree
git worktree remove .worktrees/<branch> # 删除一个Worktree
cd .worktrees/<branch> # 切换到某个Worktree
cd "$(git rev-parse --show-toplevel)" # 返回主仓库检出目录如果要将文件复制到未包含这些文件的现有Worktree中,请从主仓库运行以下命令(不要在Worktree内部运行,因为分支名称通常包含斜杠,如):
.env*feat/loginbash
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): the new worktree's configs are compared against that branch; unchanged configs are auto-trusted.release/*is permitted.direnv allow - Other branches (feature branches, PR review branches): configs are compared against the default branch; is skipped regardless, because
direnv allowcan source files that direnv does not validate..envrc
Modified configs are never auto-trusted. The script prints the manual trust command to run after review.
当存在mise或direnv配置时,脚本会尝试信任这些配置,以便钩子和脚本不会因交互式提示而阻塞。信任会基于参考分支进行基线检查:
- 受信任的基础分支(、
main、develop、dev、trunk、staging):将新Worktree的配置与该分支进行比较;未更改的配置会被自动信任,允许执行release/*。direnv allow - 其他分支(功能分支、PR评审分支):将配置与默认分支进行比较;无论如何都会跳过,因为
direnv allow可能会加载direnv未验证的文件。.envrc
修改后的配置永远不会被自动信任。脚本会输出审核后需要运行的手动信任命令。
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-workce-code-reviewbash scripts/worktree-manager.sh create <branch>feat/crowd-snifffix/email-validationworktree-jolly-beaming-ravence-workce-code-reviewbash scripts/worktree-manager.sh create <branch>feat/crowd-snifffix/email-validationworktree-jolly-beaming-ravenTroubleshooting
故障排查
"Worktree already exists": the path is already in use. Either switch to it () or remove it () before recreating.
cd .worktrees/<branch>git worktree remove .worktrees/<branch>"Cannot remove worktree: it is the current worktree": out of the worktree first, then .
cdgit worktree removeDev tool trust was skipped: the script prints the manual command. Review the config diff (), then run the printed command from the worktree directory.
git diff <base-ref> -- .envrc"Worktree已存在":该路径已被占用。可以切换到该Worktree(),或者先删除它()再重新创建。
cd .worktrees/<branch>git worktree remove .worktrees/<branch>"无法删除Worktree:它是当前Worktree":先退出该Worktree(到其他目录),再执行。
cdgit worktree remove开发工具信任被跳过:脚本会输出手动命令。查看配置差异(),然后从Worktree目录运行输出的命令。
git diff <base-ref> -- .envrc