From ai-agents
使用 git worktree 创建隔离工作空间,避免切换分支时丢失工作上下文。触发短语:"worktree"、"隔离工作空间"、"隔离分支"。
npx claudepluginhub stringke/ai-agents --plugin ai-agentsThis skill is limited to using the following tools:
使用 git worktree 在同一仓库中创建多个独立的工作目录,每个目录对应一个分支。
Creates isolated Git worktrees for experimental or risky changes, isolating work from the current branch. Performs safety checks, project setup, and baseline tests.
Creates isolated git worktrees for feature branches with prioritized directory selection, gitignore safety verification, and automatic setup for Node.js, Rust, Python, Go projects. Use before isolated feature work or implementation plans.
Creates isolated Git worktrees for feature branches with directory selection, gitignore safety verification, and auto-setup for Node.js, Python, Rust, Go projects.
Share bugs, ideas, or general feedback.
使用 git worktree 在同一仓库中创建多个独立的工作目录,每个目录对应一个分支。
.worktrees/ 目录git worktree list
如果目标分支已有 worktree,告知用户路径。
# 基于当前分支创建新分支和 worktree
git worktree add .worktrees/{branch-name} -b {branch-name}
# 基于已有分支创建 worktree
git worktree add .worktrees/{branch-name} {branch-name}
确认 worktree 目录被 git 忽略:
git check-ignore .worktrees/{branch-name}
如果未被忽略,在 .gitignore 中添加 .worktrees/。
自动检测并执行项目的初始化命令:
# 检查项目类型并安装依赖
if [ -f package.json ]; then npm install; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f Cargo.toml ]; then cargo build; fi
if [ -f go.mod ]; then go mod download; fi
if [ -f pom.xml ]; then mvn dependency:resolve; fi
if [ -f build.gradle ]; then ./gradlew dependencies; fi
告知用户 worktree 的路径和切换方式:
Worktree 已创建:.worktrees/{branch-name}
切换到该目录:cd .worktrees/{branch-name}
完成工作后(使用 /finishing-a-development-branch),清理 worktree:
git worktree remove .worktrees/{branch-name}
git worktree remove 清理引用