git-worktree-feature-flow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Worktree Feature Flow

Git Worktree 功能分支流程

Use this skill when the user wants an isolated working directory for a feature (via
git worktree
), then to merge that branch back into a target branch and clean up the worktree.
当用户需要为某个功能创建独立的工作目录(通过
git worktree
),随后将该分支合并回目标分支并清理worktree时,可使用此技能。

Examples (user prompts)

示例(用户提示)

  • "Create a worktree for
    feature/foo
    off
    main
    ."
  • "Spin up a worktree for my change, put it in
    ../wts/feature-foo
    ."
  • "Merge my worktree branch back into
    main
    with a squash merge, then clean up."
  • "Finish the worktree for
    feature/foo
    but keep the branch around."
  • "基于
    main
    分支为
    feature/foo
    创建worktree。"
  • "为我的修改创建一个worktree,将其放在
    ../wts/feature-foo
    目录下。"
  • "通过 squash 合并将我的worktree分支合并回
    main
    ,然后进行清理。"
  • "完成
    feature/foo
    的worktree工作,但保留该分支。"

Quick flow

快速流程

  1. Start: create a feature worktree
  • Ask for
    branch
    name (required).
  • Optional: ask for
    base
    ref (default: current branch).
  • Run
    scripts/worktree-start.sh
    .
  1. Work: user edits/commits in the worktree directory.
  2. Finish: merge + cleanup
  • Ask for merge
    strategy
    :
    merge
    (default),
    squash
    , or
    ff-only
    .
  • Optional: ask for
    into
    target branch (default: detected repo default branch, usually
    main
    ).
  • Run
    scripts/worktree-finish.sh
    .
  1. 开始:创建功能分支worktree
  • 询问
    branch
    分支名称(必填项)。
  • 可选:询问
    base
    基准引用(默认值:当前分支)。
  • 运行
    scripts/worktree-start.sh
    脚本。
  1. 工作:用户在worktree目录中进行编辑/提交。
  2. 完成:合并+清理
  • 询问合并
    strategy
    策略:
    merge
    (默认值)、
    squash
    ff-only
  • 可选:询问
    into
    目标分支(默认值:自动检测的仓库默认分支,通常为
    main
    )。
  • 运行
    scripts/worktree-finish.sh
    脚本。

Commands (scripts)

命令(脚本)

Start a worktree

启动worktree

bash
$HOME/.codex/skills/git-worktree-feature-flow/scripts/worktree-start.sh --branch feature/my-change
Common options:
  • --base <ref>
    : base branch/ref to branch from (default: current branch)
  • --path <dir>
    : where to place the worktree (default: sibling
    .worktrees/<repo>/<branch>
    )
    • If
      --path
      is relative, it’s interpreted relative to the repo root.
  • --yes
    : do not prompt
bash
$HOME/.codex/skills/git-worktree-feature-flow/scripts/worktree-start.sh --branch feature/my-change
常用选项:
  • --base <ref>
    :用于创建分支的基准分支/引用(默认值:当前分支)
  • --path <dir>
    :worktree的存放路径(默认值:同级目录
    .worktrees/<repo>/<branch>
    • 如果
      --path
      为相对路径,则相对于仓库根目录解析。
  • --yes
    :不进行提示,直接执行

Finish (merge back and clean up)

完成(合并回主分支并清理)

bash
$HOME/.codex/skills/git-worktree-feature-flow/scripts/worktree-finish.sh --branch feature/my-change
Common options:
  • --into <branch>
    : target branch to merge into (default: detected default branch)
  • --strategy merge|squash|ff-only
    : merge strategy (default:
    merge
    )
  • --no-delete-branch
    : keep the feature branch after merging
  • --keep-worktree
    : keep the worktree directory after merging
  • --yes
    : do not prompt
Notes:
  • --keep-worktree
    implies you should also pass
    --no-delete-branch
    (you can’t delete a branch that’s still checked out in a worktree).
  • For
    --strategy squash
    , the script creates a squash commit automatically and may force-delete the feature branch after committing (use
    --no-delete-branch
    to keep it).
bash
$HOME/.codex/skills/git-worktree-feature-flow/scripts/worktree-finish.sh --branch feature/my-change
常用选项:
  • --into <branch>
    :要合并到的目标分支(默认值:自动检测的默认分支)
  • --strategy merge|squash|ff-only
    :合并策略(默认值:
    merge
  • --no-delete-branch
    :合并后保留功能分支
  • --keep-worktree
    :合并后保留worktree目录
  • --yes
    :不进行提示,直接执行
注意事项:
  • 使用
    --keep-worktree
    时,也应同时传递
    --no-delete-branch
    参数(无法删除仍在worktree中被检出的分支)。
  • 对于
    --strategy squash
    策略,脚本会自动创建一个squash提交,合并后可能会强制删除功能分支(使用
    --no-delete-branch
    可保留该分支)。

Agent guidelines

Agent 操作指南

  • Prefer the scripts in
    scripts/
    over manually typing long
    git worktree
    commands.
  • Confirm the user’s intended
    branch
    ,
    base
    , and merge
    strategy
    before making changes.
  • Be conservative:
    • Refuse to proceed if the feature worktree has uncommitted changes unless the user explicitly wants to continue.
    • Refuse to proceed if the target worktree (where the merge happens) is dirty.
    • If cleaning up, don’t run the finish step from inside the feature worktree directory.
  • After finishing, summarize:
    • where the worktree lived,
    • what merge strategy was used,
    • whether the branch/worktree were deleted.
  • 优先使用
    scripts/
    目录下的脚本,而非手动输入冗长的
    git worktree
    命令。
  • 在进行更改前,确认用户指定的
    branch
    分支、
    base
    基准分支和合并
    strategy
    策略。
  • 操作需谨慎:
    • 如果功能分支worktree存在未提交的更改,除非用户明确要求继续,否则拒绝执行后续步骤。
    • 如果目标worktree(执行合并操作的目录)存在未提交更改,拒绝执行后续步骤。
    • 清理时,不要在功能分支worktree目录内执行完成步骤。
  • 完成操作后,总结以下信息:
    • worktree的存放路径,
    • 使用的合并策略,
    • 是否已删除分支/worktree。