/oh:git-worktree add [<path>] | migrate <target> | list | remove <path> | prune -b <branch> -o --from <source> --stash --track --guess-remote --detach --lockfrom oh
Use when creating isolated Git worktrees for parallel feature development, managing branch-based workspaces, or needing to switch between contexts without losing uncommitted work.
Ships in oh. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
管理 Git worktree,支持智能默认、IDE 集成和内容迁移。
💡 建议: 执行本命令前,建议先运行
/clear命令清理上下文,以获得更好的分析效果。
| 选项 | 说明 |
|---|---|
add [<path>] | 在 ../.zcf/项目名/<path> 添加新的 worktree |
migrate <target> | 迁移内容到指定 worktree |
list | 列出所有 worktree 及其状态 |
remove <path> | 删除指定路径的 worktree |
prune | 清理无效的 worktree 引用 |
-b <branch> | 创建新分支并检出到 worktree |
-o, --open | 创建成功后直接用 IDE 打开 |
--from <source> | 指定迁移源路径(migrate 专用) |
--stash | 迁移当前 stash 内容(migrate 专用) |
--track | 设置新分支跟踪对应的远程分支 |
--guess-remote | 自动猜测远程分支进行跟踪 |
--detach | 创建分离 HEAD 的 worktree |
--lock | 创建后锁定 worktree |
环境检查
git rev-parse --is-inside-work-tree 验证 Git 仓库智能路径管理
../.zcf/项目名/<path> 目录创建 worktreeWorktree 操作
智能默认
-b 时,使用路径名创建新分支环境文件处理
.gitignore 中列出的环境文件get_main_repo_path() {
local git_common_dir=$(git rev-parse --git-common-dir 2>/dev/null)
local current_toplevel=$(git rev-parse --show-toplevel 2>/dev/null)
# 检测是否在 worktree 中
if [[ "$git_common_dir" != "$current_toplevel/.git" ]]; then
# 在 worktree 中,从 git-common-dir 推导主仓库路径
dirname "$git_common_dir"
else
# 在主仓库中
echo "$current_toplevel"
fi
}
MAIN_REPO_PATH=$(get_main_repo_path)
PROJECT_NAME=$(basename "$MAIN_REPO_PATH")
WORKTREE_BASE="$MAIN_REPO_PATH/../.zcf/$PROJECT_NAME"
关键点: 在现有 worktree 内创建新 worktree 时,始终使用绝对路径以防止路径嵌套问题。
copy_environment_files() {
local main_repo="$MAIN_REPO_PATH"
local target_worktree="$ABSOLUTE_WORKTREE_PATH"
local gitignore_file="$main_repo/.gitignore"
if [[ ! -f "$gitignore_file" ]]; then
return 0
fi
# 检测 .env 文件
if [[ -f "$main_repo/.env" ]] && grep -q "^\.env$" "$gitignore_file"; then
cp "$main_repo/.env" "$target_worktree/.env"
echo "✅ 已复制 .env"
fi
# 检测 .env.* 模式文件(排除 .env.example)
for env_file in "$main_repo"/.env.*; do
if [[ -f "$env_file" ]] && [[ "$(basename "$env_file")" != ".env.example" ]]; then
local filename=$(basename "$env_file")
if grep -q "^\.env\.\*$" "$gitignore_file"; then
cp "$env_file" "$target_worktree/$filename"
echo "✅ 已复制 $filename"
fi
fi
done
}
支持的 IDE(按优先级):
自定义配置:
# 配置自定义 IDE
git config worktree.ide.custom.sublime "subl %s"
git config worktree.ide.preferred "sublime"
# 控制自动检测
git config worktree.ide.autodetect true # 默认
# 基本用法
git worktree add feature-ui # 从 main/master 创建新分支
git worktree add feature-ui -b my-feature # 创建新分支,路径为 feature-ui
git worktree add feature-ui -o # 创建并直接用 IDE 打开
# 内容迁移
git worktree add feature-ui -b feature/new-ui # 创建新功能 worktree
# 然后迁移未提交改动或 stash 内容
# 管理操作
git worktree list # 查看所有 worktree
git worktree remove feature-ui # 删除不需要的 worktree
git worktree prune # 清理无效引用
示例输出:
✅ Worktree created at ../.zcf/项目名/feature-ui
✅ 已复制 .env
✅ 已复制 .env.local
📋 已从 .gitignore 复制 2 个环境文件
🖥️ 是否在 IDE 中打开?[y/n]: y
🚀 正在用 VS Code 打开...
parent-directory/
├── your-project/ # 主项目
│ ├── .git/
│ └── src/
└── .zcf/ # worktree 管理
└── your-project/ # 项目 worktree
├── feature-ui/ # 功能分支
├── hotfix/ # 修复分支
└── debug/ # 调试 worktree
.git 目录,节省磁盘空间git cherry-pickWhat SKILL.md sets; muted values are Claude Code's defaults
haikunpx claudepluginhub zwmmm/oh-my-claudecode --plugin oh5 skills in this plugin
/git-clean-branchesUse when repository has dozens of stale or merged branches cluttering the namespace, or when onboarding onto a project with an overwhelming branch list./git-commitUse when preparing to commit changes and wanting structured, consistent commit messages following Conventional Commits specification./git-rollbackUse when needing to revert a branch to a previous state, undo mistaken commits, or roll back emergency hotfixes to a known-good version./uniapp-uiUniApp + UnoCSS + WotUI page generator from designs. Converts screenshots or HTML/CSS to UniApp pages. Features: intelligent component mapping with priority (custom components, then WotUI, then built-in), 6 page templates (form, list, detail, tab, search, grid), auto-analyze custom components, cross-platform compatibility checks. Use for: creating UniApp pages, converting designs to code, mobile app/mini-program/H5 development. Actions: generate, create, build, convert, analyze, design. Tech: Vue3, UnoCSS, Wot Design Uni, UniApp.Other plugins' skills for the same job