AgentSkillsCN

git-worktree

采用 Worktree 模式高效管理 Git 仓库,助力多分支并行开发。 适用场景:(1) 第一次克隆仓库时;(2) 为功能分支新建 Worktree 时;(3) 列出现有 Worktree 时;(4) 工作完成后移除 Worktree 时。 Worktree 模式仅需一次性克隆,为每个分支创建轻量级的工作目录,从而避免多次完整克隆带来的资源开销。

SKILL.md
--- frontmatter
name: git-worktree
description: |
  Manage git repositories using the worktree pattern for efficient multi-branch development.
  Use when: (1) Cloning a repository for the first time, (2) Creating a new worktree for a feature branch,
  (3) Listing existing worktrees, (4) Removing worktrees after work is complete.
  The worktree pattern clones once and creates lightweight working directories for each branch,
  avoiding the overhead of multiple full clones.

Git Worktree Manager

Manage repositories using git worktrees. This allows working on multiple branches simultaneously without switching or stashing.

Concept

code
~/dev/personal/auto/
├── my-project/              # Main clone (bare or with default branch)
│   └── .git/
└── my-project-worktrees/    # Worktrees directory
    ├── feature-123/         # Worktree for feature branch
    ├── feature-456/         # Another feature branch
    └── hotfix-789/          # Hotfix branch

Quick Reference

ActionScript
Clone reposcripts/clone_repo.sh <repo_url> [name]
Create worktreescripts/create_worktree.sh <repo_name> <branch_name>
List worktreesscripts/list_worktrees.sh <repo_name>
Remove worktreescripts/remove_worktree.sh <repo_name> <branch_name>

Workflow Examples

Start working on a JIRA ticket

bash
# Clone if not already done
./scripts/clone_repo.sh https://github.com/org/my-app.git

# Create worktree for ticket
./scripts/create_worktree.sh my-app PROJ-123-new-feature

# Work in the worktree directory
cd ~/dev/personal/auto/my-app-worktrees/PROJ-123-new-feature

Clean up after PR merged

bash
./scripts/remove_worktree.sh my-app PROJ-123-new-feature

Integration

Uses workspace-manager to determine the work directory. Repositories are cloned to <workspace_path>/<repo_name>/ and worktrees are created in <workspace_path>/<repo_name>-worktrees/.