SuperAPI AI 工具集

git-worktree

编程与开发

查看项目

更新于 10-16 08:45

技能介绍

用途:管理 Git worktree,让同一仓库的多个分支可同时检出到不同目录并行工作,无需反复切换分支或重新克隆。触发关键词包括 worktree、并行开发、多分支同时进行、工作目录。

主要能力:多个 worktree 共享同一对象库(提交/tree/blob/refs);每个 worktree 拥有独立 HEAD 与索引;同一分支不能同时被两个 worktree 检出;任一 worktree 的提交进入同一历史。

使用方式: 检出已有分支:git worktree add ../wt-{repo}-hotfix fix/hotfix-123 新建分支并检出:git worktree add -b feat/new-feature ../wt-{repo}-new-feat main 分离模式查看标签或提交:git worktree add --detach ../wt-{repo}-review v1.2.3 列出:git worktree list 移除:git worktree remove ../wt-{repo}-hotfix 目录被手动删除后清理:git worktree prune 长期使用可加锁:git worktree lock / unlock;移动路径:git worktree move。命名约定为 wt-{repo-shortname}-{purpose},与仓库同级目录。

适用场景:同时开发两个功能、不影响当前工作的热修复、审阅 PR 不切分支、在旧版本上跑测试、对比两个版本。

限制与注意:仅需切换分支用 git checkout;需要完全独立副本用 git clone;临时查看单个文件用 git show branch:file。常见错误:分支已被其他 worktree 检出;目录无效时用 git worktree prune。worktree 仅含工作文件,如 .claude 等配置位于主仓库。具体收费、价格与平台信息暂未提供。