git-worktree

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Worktree

Git Worktree

Overview

概述

This skill allows you to quickly create a new git worktree for the current project. The worktree is created in the same parent directory as the current project's root, following the naming convention
PROJECT-NAME-T-BRANCH-NAME
.
本技能可帮助你快速为当前项目创建新的git worktree。该worktree会创建在当前项目根目录的父目录下,遵循命名格式
PROJECT-NAME-T-BRANCH-NAME

Workflow

工作流程

  1. Verification:
    • Verify the current directory is within a Git repository.
    • Identify the absolute path of the project's root.
  2. User Interaction: Proactively suggest values for the required parameters. Ask the user for:
    • New branch name: The name of the branch to be created. Suggest a context-aware name (e.g.,
      feat-improvement
      or
      fix-issue-123
      based on context.
    • Base branch: The branch to base the new branch on (Default: the current branch).
    Crucially, if the user does not respond to a question or provides no alternative, proceed immediately using your suggested values instead of repeating the question. The goal is to minimize friction while allowing for customization.
  3. Path Calculation: Calculate the new worktree path at the same directory level as the project root. For example, if the project is in
    /Users/user/my-project
    , the worktree will be created at
    /Users/user/my-project-T-NEW-BRANCH
    .
  4. Creation: Execute
    scripts/create_worktree.sh
    to:
    • Create the new worktree and branch.
    • Perform initial project setup (e.g.,
      flutter pub get
      ,
      npm install
      ).
  5. Confirmation: Report the location of the new worktree and any initial setup status.
  6. Management: Use
    scripts/manage_worktrees.sh
    to:
    • List all current project worktrees.
    • Interactively select and remove a specific worktree.
  1. 验证
    • 验证当前目录是否位于Git仓库内。
    • 确定项目根目录的绝对路径。
  2. 用户交互:主动建议所需参数的取值。向用户询问:
    • 新分支名称:要创建的分支名称。建议一个上下文相关的名称(例如根据上下文建议
      feat-improvement
      fix-issue-123
      )。
    • 基础分支:新分支基于的分支(默认值:当前分支)。
    重要提示:如果用户未回复问题或未提供替代值,请立即使用你建议的取值继续操作,而非重复提问。目标是在允许自定义的同时尽可能减少操作阻碍。
  3. 路径计算:计算新worktree的路径,使其与项目根目录处于同级目录。例如,如果项目位于
    /Users/user/my-project
    ,则worktree将创建在
    /Users/user/my-project-T-NEW-BRANCH
  4. 创建:执行
    scripts/create_worktree.sh
    以:
    • 创建新的worktree和分支。
    • 完成项目初始设置(例如
      flutter pub get
      npm install
      )。
  5. 确认:告知用户新worktree的位置以及初始设置的状态。
  6. 管理:使用
    scripts/manage_worktrees.sh
    来:
    • 列出当前项目的所有worktree。
    • 交互式选择并删除特定的worktree。

Usage Example

使用示例

User: "Create a worktree for this repo." Gemini: "I'll create a new worktree for you. I'll use the branch name
feat-wyatt_skills-260221
based on the current branch
main
. Is that okay, or would you like a different name?" User: "That's fine." Gemini: [Runs the script and confirms the path
/Users/huwentao/_proj/wyatt_skills-T-feat-wyatt_skills-260221
]
Another Example (Proactive/No Response): User: "Create a worktree for feature-login." Gemini: "I'll create a worktree for
feature-login
based on
main
. Starting the setup now..." Gemini: [Runs the script and confirms the path
/Users/huwentao/_proj/foo_proj-T-feature-login
]
Manage Worktrees: User: "Show my worktrees and help me delete one." Gemini: "Here are your current worktrees. Which one would you like to remove?" Gemini: [Lists worktrees and prompts for selection via
scripts/manage_worktrees.sh
]
用户:"为这个仓库创建一个worktree。" Gemini:"我将为你创建一个新的worktree。我会基于当前分支
main
使用分支名称
feat-wyatt_skills-260221
。这样可以吗?还是你想要一个不同的名称?" 用户:"可以。" Gemini:[运行脚本并确认路径
/Users/huwentao/_proj/wyatt_skills-T-feat-wyatt_skills-260221
]
另一个示例(主动处理/无回复): 用户:"为feature-login创建一个worktree。" Gemini:"我将基于
main
feature-login
创建worktree。现在开始设置..." Gemini:[运行脚本并确认路径
/Users/huwentao/_proj/foo_proj-T-feature-login
]
管理Worktree: 用户:"显示我的worktree并帮我删除一个。" Gemini:"以下是你当前的所有worktree。你想要删除哪一个?" Gemini:[通过
scripts/manage_worktrees.sh
列出worktree并提示用户选择]

Resources

资源

scripts/

scripts/

  • create_worktree.sh
    : A bash script that calculates the paths, runs
    git worktree add
    , and performs initial project setup.
    • Arguments:
      project_path
      new_branch
      base_branch
  • manage_worktrees.sh
    : A script to list and interactively remove worktrees.
    • Arguments:
      project_path
  • create_worktree.sh
    :一个bash脚本,用于计算路径、运行
    git worktree add
    并完成项目初始设置。
    • 参数:
      project_path
      new_branch
      base_branch
  • manage_worktrees.sh
    :一个用于列出并交互式删除worktree的脚本。
    • 参数:
      project_path