AgentSkillsCN

git-worktree

管理Git工作树,以支持并行开发。当用户想要创建新的工作树、在独立的工作树中开发新功能、列出现有的工作树、清理已合并的工作树,或以“新建工作树”、“并行分支”、“用于X功能的工作树”等变体形式使用时,可使用此技能。可通过“创建工作树”“在工作树中开始新功能”“查看我的工作树”“清理工作树”或“我想并行开发X”等指令触发。

SKILL.md
--- frontmatter
name: git-worktree
description: Manage git worktrees for parallel development. Use when the user wants to create a new worktree, work on a feature in a separate worktree, list existing worktrees, clean up merged worktrees, or any variation of "new worktree", "parallel branch", "worktree for feature X". Triggers on requests like "create a worktree", "start a new feature in a worktree", "show my worktrees", "clean up worktrees", or "I want to work on X in parallel".

Git Worktree

Manage git worktrees so developers can work on multiple branches in parallel without stashing or switching.

Create a worktree

Run the bundled script from the repo root:

bash
bash <skill-path>/scripts/create-worktree.sh <branch-name> [base-branch]
  • branch-name — the new branch to create (required)
  • base-branch — branch to base it on (defaults to main)

The script creates the worktree at .worktrees/<repo>-<branch> and adds .worktrees to .gitignore.

After creation, tell the user the worktree path so they can open it in their editor or run a second Claude Code session in it.

List worktrees

bash
git worktree list

Show the output to the user in a readable format.

Clean up merged worktrees

Run the bundled cleanup script from the repo root:

bash
bash <skill-path>/scripts/cleanup-worktrees.sh

This removes worktrees whose branches have been merged into main and deletes those branches.

Important notes

  • Always run worktree commands from the main repo root, not from inside a worktree.
  • Never delete a worktree without checking if its branch is merged first.
  • If the user asks to "remove" or "delete" a specific worktree, use git worktree remove <path> and confirm with the user before deleting the branch.