git%3Acreate-worktree by neolabhq/context-engineering-kit
npx skills add https://github.com/neolabhq/context-engineering-kit --skill git:create-worktree你的任务是创建和设置用于并行开发的 git 工作树,并自动检测和安装项目依赖项。
关键:请严格按照以下步骤执行:
检查当前状态:运行 git worktree list 以显示现有工作树,并运行 git status 以验证仓库状态是否干净(没有可能导致问题的未提交更改)
获取最新的远程分支:运行 git fetch --all 以确保本地知晓所有远程分支
解析用户输入:确定用户想要创建什么:
* `<名称>`:创建具有自动检测类型前缀的工作树
* `--list`:仅显示现有工作树并退出
* 无输入:以交互方式向用户询问名称
4. 根据名称自动检测分支类型:检查第一个单词是否为已知的分支类型。如果是,则将其用作前缀,其余部分用作名称。如果不是,则默认为 feature/。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
已知类型: feature, feat, fix, bug, bugfix, hotfix, release, docs, test, refactor, chore, spike, experiment, review
示例:
* `refactor auth system` → `refactor/auth-system`
* `fix login bug` → `fix/login-bug`
* `auth system` → `feature/auth-system` (默认)
* `hotfix critical error` → `hotfix/critical-error`
名称规范化: 将空格转换为短横线,小写,移除除短横线/下划线外的特殊字符
* `<前缀>/<规范化名称>` (例如,`feature/auth-system`)
b. 分支解析:确定分支是存在于本地、远程,还是需要创建:
* 如果分支存在于本地:`git worktree add ../<项目>-<名称> <分支>`
* 如果分支存在于远程 (origin/):`git worktree add --track -b <分支> ../<项目>-<名称> origin/<分支>`
* 如果分支不存在:向用户询问基础分支(默认:当前分支或 main/master),然后 `git worktree add -b <分支> ../<项目>-<名称> <基础分支>`
c. 路径约定:使用模式为 ../<项目名称>-<名称> 的兄弟目录
* 从当前目录提取项目名称
* 使用规范化名称(而不是带前缀的完整分支名称)
* 示例:`feature/auth-system` → `../myproject-auth-system`
d. 创建工作树:执行适当的 git worktree add 命令
e. 依赖项检测:检查新工作树中是否存在依赖文件,并确定是否需要设置:
* `package.json` -> Node.js 项目 (npm/yarn/pnpm/bun)
* `requirements.txt` 或 `pyproject.toml` 或 `setup.py` -> Python 项目
* `Cargo.toml` -> Rust 项目
* `go.mod` -> Go 项目
* `Gemfile` -> Ruby 项目
* `composer.json` -> PHP 项目
f. 包管理器检测(针对 Node.js 项目):
* `bun.lockb` -> 使用 `bun install`
* `pnpm-lock.yaml` -> 使用 `pnpm install`
* `yarn.lock` -> 使用 `yarn install`
* `package-lock.json` 或 默认 -> 使用 `npm install`
g. 自动设置:自动运行依赖项安装:
* cd 到工作树并运行检测到的安装命令
* 报告进度:"正在使用 [包管理器] 安装依赖项..."
* 如果安装失败,报告错误但继续显示工作树创建摘要
6. 摘要:显示已创建工作树的摘要:
* 工作树路径
* 分支名称(带前缀的完整名称)
* 设置状态(依赖项已安装或失败)
* 快速导航命令:`cd <工作树路径>`
工作树被创建为兄弟目录以保持组织性:
~/projects/
myproject/ # 主工作树(当前目录)
myproject-add-auth/ # 功能分支工作树 (feature/add-auth)
myproject-critical-bug/ # 热修复工作树 (hotfix/critical-bug)
myproject-pr-456/ # PR 审查工作树 (review/pr-456)
命名规则:
<项目名称>-<名称> (使用名称部分,而不是完整的分支名称)<类型前缀>/<名称> (例如,feature/add-auth)<名称> 部分以保持简洁功能工作树(默认):
> /git:create-worktree auth system
# 分支:feature/auth-system
# 创建:../myproject-auth-system
修复工作树:
> /git:create-worktree fix login error
# 分支:fix/login-error
# 创建:../myproject-login-error
重构工作树:
> /git:create-worktree refactor api layer
# 分支:refactor/api-layer
# 创建:../myproject-api-layer
热修复工作树:
> /git:create-worktree hotfix critical bug
# 分支:hotfix/critical-bug
# 创建:../myproject-critical-bug
列出现有工作树:
> /git:create-worktree --list
# 显示:git worktree list 输出
使用 pnpm 的 Node.js 项目:
Detected Node.js project with pnpm-lock.yaml
Installing dependencies with pnpm...
✓ Dependencies installed successfully
Python 项目:
Detected Python project with requirements.txt
Installing dependencies with pip...
✓ Dependencies installed successfully
Rust 项目:
Detected Rust project with Cargo.toml
Building project with cargo...
✓ Project built successfully
> /git:create-worktree new dashboard
# 分支:feature/new-dashboard
# 创建工作树,安装依赖项,准备编码
# 在主工作树中,正在开发功能
> /git:create-worktree hotfix critical bug
# 分支:hotfix/critical-bug
# 从 main/master 创建独立的工作树
# 在热修复工作树中修复错误
# 完成后返回功能工作树
> /git:create-worktree review pr 123
# 分支:review/pr-123
# 为审查 PR 创建工作树
# 可以运行测试,检查代码
# 审查完成后删除
> /git:create-worktree spike new architecture
# 分支:spike/new-architecture
# 为实验创建隔离的工作树
# 根据结果丢弃或合并
分支锁定:每个分支一次只能在一个工作树中检出。如果一个分支已经被检出,该命令将告知你在哪个工作树中拥有它。
共享 .git:所有工作树共享同一个 Git 对象数据库。在任何工作树中提交的更改对所有其他工作树都可见。
干净的工作目录:该命令会检查未提交的更改,如果存在则会发出警告,因为在干净状态下创建工作树最安全。
兄弟目录:工作树始终创建为兄弟目录(使用 ../)以保持工作空间的组织性。切勿在主仓库内创建工作树。
自动依赖项安装:该命令自动检测项目类型和包管理器,然后无需提示即可运行适当的安装命令。
远程跟踪:对于远程分支,工作树会使用正确的跟踪设置(--track 标志)创建,以便拉取/推送正常工作。
当完成一个工作树时,请使用适当的移除命令:
git worktree remove ../myproject-add-auth
或者对于具有未提交更改的工作树:
git worktree remove --force ../myproject-add-auth
切勿使用 rm -rf 删除工作树 - 始终使用 git worktree remove。
"分支已被检出"
git worktree list 查看分支在何处被检出"无法创建工作树 - 路径已存在"
"依赖项安装失败"
cd ../myproject-<名称>"检测到错误的类型"
fix, hotfix, docs, test, refactor, chore, spike, reviewfeature/每周安装次数
229
仓库
GitHub 星标数
708
首次出现
2026年2月19日
安装于
opencode223
codex222
github-copilot222
gemini-cli221
kimi-cli219
cursor219
Your job is to create and setup git worktrees for parallel development, with automatic detection and installation of project dependencies.
CRITICAL: Perform the following steps exactly as described:
Current state check : Run git worktree list to show existing worktrees and git status to verify the repository state is clean (no uncommitted changes that might cause issues)
Fetch latest remote branches : Run git fetch --all to ensure local has knowledge of all remote branches
Parse user input : Determine what the user wants to create:
<name>: Create worktree with auto-detected type prefix--list: Just show existing worktrees and exitAuto-detect branch type from name : Check if the first word is a known branch type. If yes, use it as the prefix and the rest as the name. If no, default to feature/.
Known types: feature, feat, fix, bug, bugfix, hotfix, release, docs, test, refactor, chore, spike, ,
Examples:
* `refactor auth system` → `refactor/auth-system`
* `fix login bug` → `fix/login-bug`
* `auth system` → `feature/auth-system` (default)
* `hotfix critical error` → `hotfix/critical-error`
Name normalization: Convert spaces to dashes, lowercase, remove special characters except dashes/underscores
For each worktree to create : a. Branch name construction : Build full branch name from detected type and normalized name:
<prefix>/<normalized-name> (e.g., feature/auth-system)b. Branch resolution : Determine if the branch exists locally, remotely, or needs to be created:
* If branch exists locally: `git worktree add ../<project>-<name> <branch>`
* If branch exists remotely (origin/): `git worktree add --track -b <branch> ../<project>-<name> origin/<branch>`
* If branch doesn't exist: Ask user for base branch (default: current branch or main/master), then `git worktree add -b <branch> ../<project>-<name> <base>`
c. Path convention : Use sibling directory with pattern ../<project-name>-<name>
* Extract project name from current directory
* Use the normalized name (NOT the full branch with prefix)
* Example: `feature/auth-system` → `../myproject-auth-system`
d. Create the worktree : Execute the appropriate git worktree add command
e. Dependency detection : Check the new worktree for dependency files and determine if setup is needed:
* `package.json` -> Node.js project (npm/yarn/pnpm/bun)
* `requirements.txt` or `pyproject.toml` or `setup.py` -> Python project
* `Cargo.toml` -> Rust project
* `go.mod` -> Go project
* `Gemfile` -> Ruby project
* `composer.json` -> PHP project
f. Package manager detection (for Node.js projects):
* `bun.lockb` -> Use `bun install`
* `pnpm-lock.yaml` -> Use `pnpm install`
* `yarn.lock` -> Use `yarn install`
* `package-lock.json` or default -> Use `npm install`
g. Automatic setup : Automatically run dependency installation:
* cd to worktree and run the detected install command
* Report progress: "Installing dependencies with [package manager]..."
* If installation fails, report the error but continue with worktree creation summary
6. Summary : Display summary of created worktrees:
* Worktree path
* Branch name (full name with prefix)
* Setup status (dependencies installed or failed)
* Quick navigation command: `cd <worktree-path>`
Worktrees are created as sibling directories to maintain organization:
~/projects/
myproject/ # Main worktree (current directory)
myproject-add-auth/ # Feature branch worktree (feature/add-auth)
myproject-critical-bug/ # Hotfix worktree (hotfix/critical-bug)
myproject-pr-456/ # PR review worktree (review/pr-456)
Naming rules:
<project-name>-<name> (uses the name part, NOT the full branch)<type-prefix>/<name> (e.g., feature/add-auth)<name> portion for brevityFeature worktree (default):
> /git:create-worktree auth system
# Branch: feature/auth-system
# Creates: ../myproject-auth-system
Fix worktree:
> /git:create-worktree fix login error
# Branch: fix/login-error
# Creates: ../myproject-login-error
Refactor worktree:
> /git:create-worktree refactor api layer
# Branch: refactor/api-layer
# Creates: ../myproject-api-layer
Hotfix worktree:
> /git:create-worktree hotfix critical bug
# Branch: hotfix/critical-bug
# Creates: ../myproject-critical-bug
List existing worktrees:
> /git:create-worktree --list
# Shows: git worktree list output
Node.js project with pnpm:
Detected Node.js project with pnpm-lock.yaml
Installing dependencies with pnpm...
✓ Dependencies installed successfully
Python project:
Detected Python project with requirements.txt
Installing dependencies with pip...
✓ Dependencies installed successfully
Rust project:
Detected Rust project with Cargo.toml
Building project with cargo...
✓ Project built successfully
> /git:create-worktree new dashboard
# Branch: feature/new-dashboard
# Creates worktree, installs dependencies, ready to code
# In main worktree, working on feature
> /git:create-worktree hotfix critical bug
# Branch: hotfix/critical-bug
# Creates separate worktree from main/master
# Fix bug in hotfix worktree
# Return to feature work when done
> /git:create-worktree review pr 123
# Branch: review/pr-123
# Creates worktree for reviewing PR
# Can run tests, inspect code
# Delete when review complete
> /git:create-worktree spike new architecture
# Branch: spike/new-architecture
# Creates isolated worktree for experimentation
# Discard or merge based on results
Branch lock : Each branch can only be checked out in one worktree at a time. If a branch is already checked out, the command will inform you which worktree has it.
Shared .git : All worktrees share the same Git object database. Changes committed in any worktree are visible to all others.
Clean working directory : The command checks for uncommitted changes and warns if present, as creating worktrees is safest with a clean state.
Sibling directories : Worktrees are always created as sibling directories (using ../) to keep the workspace organized. Never create worktrees inside the main repository.
Automatic dependency installation : The command automatically detects the project type and package manager, then runs the appropriate install command without prompting.
Remote tracking : For remote branches, worktrees are created with proper tracking setup (--track flag) so pulls/pushes work correctly.
When done with a worktree, use the proper removal command:
git worktree remove ../myproject-add-auth
Or for a worktree with uncommitted changes:
git worktree remove --force ../myproject-add-auth
Never use rm -rf to delete worktrees - always use git worktree remove.
"Branch is already checked out"
git worktree list to see where the branch is checked out"Cannot create worktree - path already exists"
"Dependency installation failed"
cd ../myproject-<name>"Wrong type detected"
fix, hotfix, docs, test, refactor, chore, spike, reviewfeature/ when first word isn't a known typeWeekly Installs
229
Repository
GitHub Stars
708
First Seen
Feb 19, 2026
Installed on
opencode223
codex222
github-copilot222
gemini-cli221
kimi-cli219
cursor219
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
144,300 周安装
PWA开发指南:构建渐进式Web应用,实现离线工作与原生应用体验
822 周安装
tRPC 端到端类型安全指南 - TypeScript API 开发与 React/Next.js 集成
804 周安装
ML Pipeline专家指南:生产级机器学习流水线架构、编排与自动化部署
819 周安装
设计系统构建指南:Figma、Airbnb专家框架,助您规模化产品设计
820 周安装
PPTX 文件处理全攻略:Python 脚本创建、编辑、分析 .pptx 文件内容与结构
824 周安装
Trigger.dev 实时功能:从前端/后端实时订阅任务运行,流式传输数据
822 周安装
experimentreview