linear-worktree
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineselinear-worktree
linear-worktree
Creates a git worktree from for a Linear issue as a sibling directory of the current repo.
mainCopy and track this checklist:
text
Worktree creation progress:
- [ ] Step 1: Resolve REPO_ROOT / REPO_NAME / REPOS_BASE
- [ ] Step 2: Parse input into ISSUE_ID and BRANCH
- [ ] Step 3: git fetch origin main
- [ ] Step 4: git worktree add at $REPOS_BASE/$REPO_NAME-$ISSUE_ID
- [ ] Step 5: Report worktree path, branch, and cd command with resolved paths为Linear议题基于分支在当前仓库的同级目录创建git worktree。
main复制并跟踪以下检查清单:
text
Worktree creation progress:
- [ ] Step 1: Resolve REPO_ROOT / REPO_NAME / REPOS_BASE
- [ ] Step 2: Parse input into ISSUE_ID and BRANCH
- [ ] Step 3: git fetch origin main
- [ ] Step 4: git worktree add at $REPOS_BASE/$REPO_NAME-$ISSUE_ID
- [ ] Step 5: Report worktree path, branch, and cd command with resolved pathsSetup
配置步骤
Resolve three variables:
- Inside a git repo (most common): =
REPO_ROOT,git rev-parse --show-toplevel= its basename,REPO_NAME= its parent directory.REPOS_BASE - Not inside a git repo but has
config.json: use that asrepos_base. Ask the user which repo folder.REPOS_BASE - Neither: ask for the full repo path.
解析三个变量:
- 处于git仓库内(最常见场景):=
REPO_ROOT的结果,git rev-parse --show-toplevel= 仓库根目录的名称,REPO_NAME= 仓库根目录的父目录。REPOS_BASE - 不在git仓库内但包含
config.json:使用该值作为repos_base,询问用户选择哪个仓库文件夹。REPOS_BASE - 以上两种情况都不满足:询问用户提供完整的仓库路径。
Inputs
输入格式
The user provides one of:
- Linear URL:
https://linear.app/myteam/issue/ABC-58/add-dark-mode-toggle - Copy as prompt:
ABC-58 Add dark mode toggle to settings page - Issue ID only:
ABC-58
用户可提供以下任意一种输入:
- Linear URL:
https://linear.app/myteam/issue/ABC-58/add-dark-mode-toggle - 复制为提示语:
ABC-58 Add dark mode toggle to settings page - 仅议题ID:
ABC-58
Parsing
解析规则
All parsing produces two values: (lowercased) and (id + slug).
ISSUE_IDBRANCH所有输入解析后都会生成两个值:(转为小写)和(ID + 短标识)。
ISSUE_IDBRANCHFrom URL
从URL解析
- Extract issue ID from the path segment after →
/issue/=ISSUE_IDabc-58 - Last path segment becomes the slug → =
BRANCHabc-58-add-dark-mode-toggle
- 从后的路径段提取议题ID →
/issue/=ISSUE_IDabc-58 - 最后一个路径段作为短标识 → =
BRANCHabc-58-add-dark-mode-toggle
From copy as prompt
从「复制为提示语」解析
- First token is the issue ID → =
ISSUE_IDabc-58 - Slugify the rest: lowercase, spaces to , strip backticks/parentheses/
-/quotes/.../#, collapse consecutive hyphens, trim leading/trailing hyphens@ - =
BRANCHabc-58-<slug>
Example:
→
ABC-58 Add dark mode toggle (don't break "light" default)abc-58-add-dark-mode-toggle-dont-break-light-default- 第一个标记为议题ID → =
ISSUE_IDabc-58 - 将剩余内容转为短标识:转为小写,空格替换为,移除反引号/括号/
-/引号/.../#,合并连续的连字符,去除首尾连字符@ - =
BRANCHabc-58-<短标识>
示例:
→
ABC-58 Add dark mode toggle (don't break "light" default)abc-58-add-dark-mode-toggle-dont-break-light-defaultFrom issue ID only
从仅议题ID解析
Lowercase the ID → = . Slugify any description the user provides for the branch, otherwise = .
ISSUE_IDabc-58BRANCHabc-58将ID转为小写 → = 。如果用户提供了分支描述,则将描述转为短标识;否则 = 。
ISSUE_IDabc-58BRANCHabc-58Worktree Creation
Worktree创建
bash
git -C $REPO_ROOT fetch origin main
git -C $REPO_ROOT worktree add \
-b $BRANCH \
$REPOS_BASE/$REPO_NAME-$ISSUE_ID \
mainThis creates a worktree at (e.g. ) — a sibling of the main repo, not inside it.
$REPOS_BASE/$REPO_NAME-$ISSUE_ID/Users/you/Code/myrepo-abc-58bash
git -C $REPO_ROOT fetch origin main
git -C $REPO_ROOT worktree add \
-b $BRANCH \
$REPOS_BASE/$REPO_NAME-$ISSUE_ID \
main此命令会在(例如)创建worktree —— 位于主仓库的同级目录,而非仓库内部。
$REPOS_BASE/$REPO_NAME-$ISSUE_ID/Users/you/Code/myrepo-abc-58After Creation
创建完成后
Tell the user the worktree path, branch name, and command using actual resolved paths:
cdWorktree: /Users/you/Code/myrepo-abc-58
Branch: abc-58-add-dark-mode-toggle
Run: cd /Users/you/Code/myrepo-abc-58告知用户worktree路径、分支名称以及使用实际解析路径的命令:
cdWorktree: /Users/you/Code/myrepo-abc-58
Branch: abc-58-add-dark-mode-toggle
Run: cd /Users/you/Code/myrepo-abc-58Edge Cases and Gotchas
边缘情况与注意事项
- Branch exists but not checked out: drop — use
-b.git worktree add $REPOS_BASE/$REPO_NAME-$ISSUE_ID $BRANCH - Branch checked out in another worktree: do not . Run
--forceand tell the user togit worktree listto the existing worktree.cd - Directory already exists: confirm with user before removing — may be a forgotten worktree.
- Always fetch first: before
git fetch origin main, or the worktree gets a stale base.git worktree add - Sibling, not child: worktree path is next to , never inside it.
$REPO_ROOT - "Create a branch" means worktree: use , not
git worktree add.git checkout -b - Always end with : the worktree is useless if the user stays in the original repo.
cd
- 分支已存在但未检出:去掉参数 —— 使用
-b。git worktree add $REPOS_BASE/$REPO_NAME-$ISSUE_ID $BRANCH - 分支已在另一个worktree中检出:不要使用。执行
--force并告知用户切换到已存在的worktree目录。git worktree list - 目录已存在:在删除前需确认用户 —— 该目录可能是被遗忘的worktree。
- 始终先执行fetch:在前执行
git worktree add,否则worktree会基于过时的代码。git fetch origin main - 同级目录而非子目录:worktree路径位于的同级,绝不能在仓库内部。
$REPO_ROOT - 「创建分支」指创建worktree:使用而非
git worktree add。git checkout -b - 始终以cd命令结尾:如果用户停留在原仓库,worktree将无法使用。