git-worktrees
Use when worktrees, isolated branches/work directories, or project-required isolation are involved; create, enter and clean up Git worktrees.
Skill by cheng6563
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/cheng6563-git-worktrees
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
- Runs as
- Shell scripts
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/git-worktrees
What's inside
- Skill name
git-worktrees- Description
- Use when worktrees, isolated branches/work directories, or project-required isolation are involved; create, enter and clean up Git worktrees.
- License
- MIT
- Instructions
- 80 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (3)
- SKILL.md
- worktree.ps1 · scripts/
- worktree.sh · scripts/
SKILL.md (first lines)
# 使用 Git Worktrees **从目标代码定位所属仓库 → 工作分支基于最新远端主干 → 创建后校验 common dir。定位、创建、校验、清理一律调用配套脚本,禁止手写 `git worktree add/remove`。** ## 0. 找到配套脚本 `SKILL_DIR` = **你刚读取的这个 SKILL.md 所在的目录**(平台加载技能时给出的 base directory,或技能列表里 SKILL.md 路径的父目录)。脚本固定在 `SKILL_DIR/scripts/` 下。调用时一律拼成绝对路径;相对路径会按当前工作目录解析,不能用。 按你当前所在的 shell 直接调用,**不要套一层新的 shell 进程**: - 当前是 PowerShell(Windows PowerShell 5.1 或 PowerShell 7):用调用运算符直接执行:`& "$SKILL_DIR/scripts/worktree.ps1" <子命令> ...` - 当前是 bash / Git Bash:`bash "$SKILL_DIR/scripts/worktree.sh" <子命令> ...` 禁止 `pwsh -File ...`、`powershell -File ...`,也禁止从 bash 再启动 pwsh 去调用 `.ps1`。脚本兼容 Windows PowerShell 5.1 和 PowerShell 7。PowerShell 中的退出码看 `$LASTEXITCODE`。 如果拿不到这个 SKILL.md 的路径,按以下顺序找,找到第一个即停: 1. 环境变量 `LITEPOWERS_SKILL_DIR`(指向本技能目录); 2. 在已知技能根目录下找 `git-worktrees/scripts/worktree.sh`:项目内 `.agents/skills`、`.claude/skills`、`.cursor/skills`;用户目录下 `~/.agents/skills`、`~/.claude/skills`、`~/.claude/plugins`、`~/.codex/skills`、`~/.pi/agent/skills`、`~/.cursor/skills`。 确认用的是哪一份:执行 `worktree where`,看输出的 `skill_dir`。仍然找不到就停止并告知用户,不要退回手写命令。 ## 输出约定 输出为 `key=value` 行;失败时 stderr 输出 `error=...` 且退出码为 1。退出码 3 仅用于 `remove` 留有残留文件的情况,见第 4 步。**任何非 0 退出都立即停止,向用户报告 error 原文,不要自行绕过或改用手写命令。** `<代码路径>` 传本次要修改的文件或目录(可以不存在,脚本会往上找已存在的祖先目录)。嵌套仓库(外层仓里有被忽略的独立子仓)时,务必传子仓里的路径,不要传外层根目录。 ## 1. 定位 ``` worktree locate <代码路径> ``` 关键字段:`source_root`(目标仓主检出根)、`session_matches`(当前会话目录是否就在该仓)、`outer_repo`(有值说明是嵌套子仓)。`source_root` 与预期项目不符时停止,换正确的代码路径。 ## 2. 创建 平台若提供原生 worktree 工具,可以使用,但它不一定以 `source_root` 为目标仓(`git -C` 不会改变它的上下文)。用完必须执行第 3 步校验。其余情况用脚本创建: ``` worktree create <代码路径> <分支名> [--base origin/xxx] [--parent <目录>] ``` (PowerShell 参数写法为 `-Base` / `-Parent` / `-NoFetch`。) 脚本会做这些事:先 fetch,再基于 `origin/master`(没有就用 `origin/main`)切出新分支;创建后自动校验。 创建位置为 `<父目录>/<分支名>`,父目录按以下优先级确定(输出里的 `parent_source` 会标明用的是哪一级): 1. 参数 `--parent <目录>`:用户明确指定位置时才传; 2. 环境变量 `LITEPOWERS_WORKTREE_DIR`; 3. 项目约定:目标仓的 `git config litepowers.worktreeDir`; 4. 默认:`source_root/.worktrees`。 后两级的相对路径都相对于 `source_root`。父目录在仓内且尚未被忽略时,脚本会把它写入该仓的 `.git/info/exclude`,不会修改 `.gitignore`。`.claude/worktrees` 只是 Claude Code 自带工具的约定,脚本不使用它。 创建成功后,后续所有读写和 Git 操作都以输出的 `worktree` 为根。 ## 3. 校验(原生工具创建后必做) ``` worktree verify <worktree路径> <代码路径> ``` 输出 `status=ok` 才能继续。校验失败说明建到了错误的仓:不要在里面改代码;报告目标仓、实际路径和 common dir;有未提交改动时先和用户确认,不要自动删除。 ## 4. 清理 原生工具创建的,优先用原生工具清理。其他情况: ``` worktree remove <worktree路径> <代码路径> [--force] ``` 脚本会先校验归属;有未提交改动时拒绝删除(`--force` 需用户明确同意)。只用 `git worktree remove` 删除一次,不会重试;分支不会被删除。 退出码 3、输出 `status=removed_with_residue` 表示 worktree 已从 Git 注销,但 `residue` 指向的目录还有文件残留(通常是 Windows 上文件被其他程序占用)。这时把 `residue` 路径告诉用户并停止:不要重试,不要手动删除,不要结束任何进程。
From cheng6563/litepowers, MIT.
More from cheng6563/litepowers
- 0.584score
align
cheng6563
Use for new non-trivial development, unresolved bug fixes, or first repair after diagnosis with an open approach; not read-only review, explicit small…
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
code-as-spec
cheng6563
Use to maintain internal business docs, place project rules, or manage temporary acceptance input for opted-in alignment-driven review; not wording-only edits.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
deep-research
cheng6563
Use for explicit deep research or consequential questions with fragmented/conflicting evidence benefiting from independent subquestions.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
delegation
cheng6563
Use for review, explicit delegation, substantial repetitive/batch work, or multi-step workflow validation; not single commands or tasks forbidding delegation.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
systematic-debugging
cheng6563
Use to investigate unknown failures, business incident reports, or incomplete diagnoses after align, within active tasks, or on diagnosis-only requests; not…
SkillAFreshness: A★ 1Claude Code +9 - 0.576score
tdd
cheng6563
Use only when align selects test-first work or the user explicitly invokes TDD; never invoke autonomously.
SkillAFreshness: A★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Oct 16, 2026 (13 days ago)
- Last release
- Oct 24, 2026 (5 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/cheng6563/litepowers
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from cheng6563
- 0.584score
align
cheng6563
Use for new non-trivial development, unresolved bug fixes, or first repair after diagnosis with an open approach; not read-only review, explicit small…
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
code-as-spec
cheng6563
Use to maintain internal business docs, place project rules, or manage temporary acceptance input for opted-in alignment-driven review; not wording-only edits.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
deep-research
cheng6563
Use for explicit deep research or consequential questions with fragmented/conflicting evidence benefiting from independent subquestions.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
delegation
cheng6563
Use for review, explicit delegation, substantial repetitive/batch work, or multi-step workflow validation; not single commands or tasks forbidding delegation.
SkillAFreshness: A★ 1Claude Code +9 - 0.584score
systematic-debugging
cheng6563
Use to investigate unknown failures, business incident reports, or incomplete diagnoses after align, within active tasks, or on diagnosis-only requests; not…
SkillAFreshness: A★ 1Claude Code +9 - 0.576score
tdd
cheng6563
Use only when align selects test-first work or the user explicitly invokes TDD; never invoke autonomously.
SkillAFreshness: A★ 1Claude Code +9
Cite this page
git-worktrees skill. Agent Mart. https://agentmart.dev/skills/cheng6563-git-worktrees (last updated 2026-10-24)