Token导航 LogoToken导航

Agent Skill · 开发

git-worktree-manager(git 工作树管理器)

git-worktree-manager 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

git-worktree-manager 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为执行命令;许可证信息还不明确,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 12,557。

总安装 1,224周安装 51GitHub Stars 103下载 408核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:git-worktree-manager(git 工作树管理器)
来源仓库:https://github.com/borghei/claude-skills
仓库路径:skills/git-worktree-manager
安装命令:
npx skills add https://github.com/borghei/claude-skills --skill git-worktree-manager
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/borghei/claude-skills --skill git-worktree-manager

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

git-worktree-manager 管理并行开发工作树,支持确定性命名、端口分配、环境同步与自动清理。适用于多代理协作场景,确保每个会话拥有独立分支、环境与运行服务,提升开发效率。通过 npx skills add 从 GitHub 安装,具体命令与配置见仓库文档。

安装前请确认权限范围与维护状态,注意是否会触发命令执行或文件系统操作。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/git-worktree-manager

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/borghei/claude-skills --skill git-worktree-man…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

git-worktree-manager 怎么安装?

在终端执行 npx skills add https://github.com/borghei/claude-skills --skill git-worktree-manager。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

git-worktree-manager 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

git-worktree-manager 需要什么权限?

权限级别是执行命令。安装流程涉及命令执行,可能通过 npx skills add https://github.com/borghei/claude-skills --skill git-worktree-manager 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

git-worktree-manager 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

git-worktree-manager 用的人多吗?

公开数据是累计安装 1,224 次,近一周安装 51 次,下载 408 次,GitHub 103 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

git-worktree-manager 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
git-worktree-manager

git 工作树管理器 · 本页

1,224103执行命令未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Git Worktree Manager

Tier: POWERFUL Category: Engineering / Developer Tooling Maintainer: Claude Skills Team

Overview

Manage parallel development workflows using Git worktrees with deterministic naming, automatic port allocation, environment file synchronization, dependency installation, and cleanup automation. Optimized for multi-agent workflows where each agent or terminal session owns an isolated worktree with its own ports, environment, and running services.

Keywords

git worktree, parallel development, branch isolation, port allocation, multi-agent development, worktree cleanup, Docker Compose worktree, concurrent branches

Core Capabilities

1. Worktree Lifecycle Management

  • Create worktrees from new or existing branches with deterministic naming
  • Copy.env files from main repo to new worktrees
  • Install dependencies based on lockfile detection
  • List all worktrees with status (clean/dirty, ahead/behind)
  • Safe cleanup with uncommitted change detection

2. Port Allocation

  • Deterministic port assignment per worktree (base + index * stride)
  • Collision detection against running processes
  • Persistent port map in .worktree-ports.json
  • Docker Compose override generation for per-worktree ports

3. Multi-Agent Isolation

  • One branch per worktree, one agent per worktree
  • No shared state between agent workspaces
  • Conflict-free parallel execution
  • Task ID mapping for traceability

4. Cleanup Automation

  • Stale worktree detection by age
  • Merged branch detection for safe removal
  • Dirty state warnings before deletion
  • Bulk cleanup with safety confirmations

When to Use

  • You need 2+ concurrent branches open with running dev servers
  • You want isolated environments for feature work, hotfixes, and PR review
  • Multiple AI agents need separate workspaces that do not interfere
  • Your current branch is blocked but a hotfix is urgent
  • You want automated cleanup instead of manual rm -rf operations

Quick Start

Create a Worktree

# Create worktree for a new feature branch
git worktree add ../wt-auth -b feature/new-auth main

# Create worktree from an existing branch
git worktree add ../wt-hotfix hotfix/fix-login

# Create worktree in a dedicated directory
git worktree add ~/worktrees/myapp-auth -b feature/auth origin/main

List All Worktrees

git worktree list
# Output:
# /Users/dev/myapp              abc1234 [main]
# /Users/dev/wt-auth            def5678 [feature/new-auth]
# /Users/dev/wt-hotfix          ghi9012 [hotfix/fix-login]

Remove a Worktree

# Safe removal (fails if there are uncommitted changes)
git worktree remove ../wt-auth

# Force removal (discards uncommitted changes)
git worktree remove --force ../wt-auth

# Prune stale metadata
git worktree prune

Port Allocation Strategy

Deterministic Port Assignment

Each worktree gets a block of ports based on its index:

Worktree Index    App Port    DB Port    Redis Port    API Port
────────────────────────────────────────────────────────────────
0 (main)          3000        5432       6379          8000
1 (wt-auth)       3010        5442       6389          8010
2 (wt-hotfix)     3020        5452       6399          8020
3 (wt-feature)    3030        5462       6409          8030

Formula: port = base_port + (worktree_index * stride) Default stride: 10

Port Map File

Store the allocation in .worktree-ports.json at the worktree root:

{
  "worktree": "wt-auth",
  "branch": "feature/new-auth",
  "index": 1,
  "ports": {
    "app": 3010,
    "database": 5442,
    "redis": 6389,
    "api": 8010
  },
  "created": "2026-03-09T10:30:00Z"
}

Port Collision Detection

# Check if a port is already in use
check_port() {
  local port=$1
  if lsof -i :"$port" > /dev/null 2>&1; then
    echo "PORT $port is BUSY"
    return 1
  else
    echo "PORT $port is FREE"
    return 0
  fi
}

# Check all ports for a worktree
for port in 3010 5442 6389 8010; do
  check_port $port
done

Full Worktree Setup Script

#!/bin/bash
# setup-worktree.sh — Create a fully prepared worktree
set -euo pipefail

BRANCH="${1:?Usage: setup-worktree.sh <branch-name> [base-branch]}"
BASE="${2:-main}"
WT_NAME="wt-$(echo "$BRANCH" | sed 's|.*/||' | tr '[:upper:]' '[:lower:]')"
WT_PATH="../$WT_NAME"
MAIN_REPO="$(git rev-parse --show-toplevel)"

echo "Creating worktree: $WT_PATH from $BASE..."

# 1. Create worktree
if git rev-parse --verify "$BRANCH" > /dev/null 2>&1; then
  git worktree add "$WT_PATH" "$BRANCH"
else
  git worktree add "$WT_PATH" -b "$BRANCH" "$BASE"
fi

# 2. Copy environment files
for envfile in .env .env.local .env.development; do
  if [ -f "$MAIN_REPO/$envfile" ]; then
    cp "$MAIN_REPO/$envfile" "$WT_PATH/$envfile"
    echo "Copied $envfile"
  fi
done

# 3. Allocate ports
WT_INDEX=$(git worktree list | grep -n "$WT_PATH" | cut -d: -f1)
WT_INDEX=$((WT_INDEX - 1))
STRIDE=10

cat > "$WT_PATH/.worktree-ports.json" << EOF
{
  "worktree": "$WT_NAME",
  "branch": "$BRANCH",
  "index": $WT_INDEX,
  "ports": {
    "app": $((3000 + WT_INDEX * STRIDE)),
    "database": $((5432 + WT_INDEX * STRIDE)),
    "redis": $((6379 + WT_INDEX * STRIDE)),
    "api": $((8000 + WT_INDEX * STRIDE))
  }
}
EOF
echo "Ports allocated (index $WT_INDEX)"

# 4. Update .env with allocated ports
if [ -f "$WT_PATH/.env" ]; then
  APP_PORT=$((3000 + WT_INDEX * STRIDE))
  DB_PORT=$((5432 + WT_INDEX * STRIDE))
  sed -i.bak "s/APP_PORT=.*/APP_PORT=$APP_PORT/" "$WT_PATH/.env"
  sed -i.bak "s/:5432/:$DB_PORT/g" "$WT_PATH/.env"
  rm -f "$WT_PATH/.env.bak"
  echo "Updated .env with worktree ports"
fi

# 5. Install dependencies
cd "$WT_PATH"
if [ -f "pnpm-lock.yaml" ]; then
  pnpm install --frozen-lockfile
elif [ -f "package-lock.json" ]; then
  npm ci
elif [ -f "yarn.lock" ]; then
  yarn install --frozen-lockfile
elif [ -f "requirements.txt" ]; then
  pip install -r requirements.txt
elif [ -f "go.mod" ]; then
  go mod download
fi

echo ""
echo "Worktree ready: $WT_PATH"
echo "Branch: $BRANCH"
echo "App port: $((3000 + WT_INDEX * STRIDE))"
echo ""
echo "Next: cd $WT_PATH && pnpm dev"

Docker Compose Per-Worktree

# docker-compose.worktree.yml — override for worktree-specific ports
# Usage: docker compose -f docker-compose.yml -f docker-compose.worktree.yml up

services:
  postgres:
    ports:
      - "${DB_PORT:-5432}:5432"
    environment:
      POSTGRES_DB: "myapp_${WT_NAME:-main}"

  redis:
    ports:
      - "${REDIS_PORT:-6379}:6379"

  app:
    ports:
      - "${APP_PORT:-3000}:3000"
    environment:
      DATABASE_URL: "postgresql://dev:dev@postgres:5432/myapp_${WT_NAME:-main}"

Launch with worktree-specific ports:

DB_PORT=5442 REDIS_PORT=6389 APP_PORT=3010 WT_NAME=auth \
  docker compose -f docker-compose.yml -f docker-compose.worktree.yml up -d

Cleanup Automation

#!/bin/bash
# cleanup-worktrees.sh — Safe worktree cleanup
set -euo pipefail

STALE_DAYS="${1:-14}"
DRY_RUN="${2:-true}"

echo "Scanning worktrees (stale threshold: ${STALE_DAYS} days)..."
echo ""

git worktree list --porcelain | while read -r line; do
  case "$line" in
    worktree\ *)
      WT_PATH="${line#worktree }"
      ;;
    branch\ *)
      BRANCH="${line#branch refs/heads/}"
      # Skip main worktree
      if [ "$WT_PATH" = "$(git rev-parse --show-toplevel)" ]; then
        continue
      fi

      # Check if branch is merged
      MERGED=""
      if git branch --merged main | grep -q "$BRANCH" 2>/dev/null; then
        MERGED=" [MERGED]"
      fi

      # Check for uncommitted changes
      DIRTY=""
      if [ -d "$WT_PATH" ]; then
        cd "$WT_PATH"
        if [ -n "$(git status --porcelain)" ]; then
          DIRTY=" [DIRTY - has uncommitted changes]"
        fi
        cd - > /dev/null
      fi

      # Check age
      if [ -d "$WT_PATH" ]; then
        AGE_DAYS=$(( ($(date +%s) - $(stat -f %m "$WT_PATH" 2>/dev/null || stat -c %Y "$WT_PATH" 2>/dev/null)) / 86400 ))
        STALE=""
        if [ "$AGE_DAYS" -gt "$STALE_DAYS" ]; then
          STALE=" [STALE: ${AGE_DAYS} days old]"
        fi
      fi

      echo "$WT_PATH ($BRANCH)$MERGED$DIRTY$STALE"

      if [ -n "$MERGED" ] && [ -z "$DIRTY" ] && [ "$DRY_RUN" = "false" ]; then
        echo "  -> Removing merged clean worktree..."
        git worktree remove "$WT_PATH"
      fi
      ;;
  esac
done

echo ""
git worktree prune
echo "Done. Run with 'false' as second arg to actually remove."

Multi-Agent Workflow Pattern

When running multiple AI agents (Claude Code, Cursor, Copilot) on the same repo:

Agent Assignment:
───────────────────────────────────────────────────
Agent 1 (Claude Code)  → wt-feature-auth   (port 3010)
Agent 2 (Cursor)       → wt-feature-billing (port 3020)
Agent 3 (Copilot)      → wt-bugfix-login   (port 3030)
Main repo              → integration (main) (port 3000)
───────────────────────────────────────────────────

Rules:
- Each agent works ONLY in its assigned worktree
- No agent modifies another agent's worktree
- Integration happens via PRs to main, not direct merges
- Port conflicts are impossible due to deterministic allocation

Decision Matrix

ScenarioAction
Need isolated dev server for a featureCreate a new worktree
Quick diff review of a branchgit diff in current tree (no worktree needed)
Hotfix while feature branch is dirtyCreate dedicated hotfix worktree
Bug triage with reproduction branchTemporary worktree, cleanup same day
PR review with running codeWorktree at PR branch, run tests
Multiple agents on same repoOne worktree per agent

Validation Checklist

After creating a worktree, verify:

  1. git worktree list shows the expected path and branch
  2. .worktree-ports.json exists with unique port assignments
  3. .env files are present and contain worktree-specific ports
  4. pnpm install (or equivalent) completed without errors
  5. Dev server starts on the allocated port
  6. Database connects on the allocated DB port
  7. No port conflicts with other worktrees or services

Common Pitfalls

  • Creating worktrees inside the main repo directory — always use ../wt-name to keep them alongside
  • Reusing localhost:3000 across all branches — causes port conflicts; use deterministic allocation
  • Sharing one DATABASE_URL across worktrees — each needs its own database or schema
  • Removing a worktree with uncommitted changes — always check dirty state before removal
  • Forgetting to prune after branch deletion — run git worktree prune to clean metadata
  • Not updating.env ports after worktree creation — the setup script should handle this automatically

Best Practices

  1. One branch per worktree, one agent per worktree — never share
  2. Keep worktrees short-lived — remove after the branch is merged
  3. Deterministic naming — use wt-<topic> pattern for easy identification
  4. Persist port mappings — store in .worktree-ports.json, not in memory
  5. Run cleanup weekly — scan for stale and merged-branch worktrees
  6. Include worktree path in terminal title — prevents wrong-window commits
  7. Never force-remove dirty worktrees — unless changes are intentionally discarded

Troubleshooting

ProblemCauseSolution
fatal: '<path>' is already checked outBranch is already active in another worktreeUse git worktree list to find where the branch is checked out, then switch to a different branch or remove the existing worktree first
Port conflict despite deterministic allocationA non-worktree process is occupying the assigned portRun lsof -i:<port> to identify the process, terminate it or adjust the stride/base in the port allocation formula
.env file missing after worktree creationSetup script was not run or .env does not exist in the main repoCopy .env manually from the main repo root, or re-run setup-worktree.sh which handles env file copying
git worktree prune reports nothing but stale paths remainWorktree directory was deleted manually without git worktree removeRun git worktree prune to clean orphaned metadata, then verify with git worktree list
Dependencies fail to install in new worktreeLockfile references a private registry or cache not available in the worktree pathEnsure .npmrc, .yarnrc.yml, or pip config files are copied alongside .env during setup
Docker Compose services start on wrong portsThe docker-compose.worktree.yml override was not included in the compose commandAlways pass both files: docker compose -f docker-compose.yml -f docker-compose.worktree.yml up
Worktree shows as dirty immediately after creationUntracked files from .env copy or generated .worktree-ports.jsonAdd .worktree-ports.json and copied env files to .gitignore in the project

Success Criteria

  • Zero port conflicts across all active worktrees measured by lsof checks returning no collisions after setup
  • Worktree creation under 60 seconds including dependency installation for projects with warm package caches
  • 100% env parity between main repo and worktrees verified by diffing .env keys (values may differ for ports)
  • Stale worktree count stays at zero when cleanup automation runs on a weekly schedule with a 14-day threshold
  • No cross-worktree interference validated by running concurrent dev servers in 3+ worktrees simultaneously without failures
  • Branch-to-worktree traceability maintained via .worktree-ports.json present in every active worktree with correct metadata
  • Cleanup safety rate of 100% meaning no worktree with uncommitted changes is ever removed without explicit --force confirmation

Scope & Limitations

This skill covers:

  • Git worktree lifecycle: creation, listing, status inspection, and removal
  • Deterministic port allocation and collision avoidance for parallel dev servers
  • Environment file synchronization and Docker Compose override patterns
  • Multi-agent workspace isolation strategies and cleanup automation

This skill does NOT cover:

  • Git branching strategies or merge conflict resolution (see pr-review-expert and release-manager)
  • Secret rotation, vault integration, or credential management (see env-secrets-manager)
  • CI/CD pipeline configuration or automated test orchestration (see ci-cd-pipeline-builder)
  • Monorepo package management, workspace linking, or cross-package dependency resolution (see monorepo-navigator)

Integration Points

SkillIntegrationData Flow
env-secrets-managerWorktree setup copies .env files that contain secrets managed by this skill.env files flow from main repo to each worktree; secret references remain consistent across all copies
ci-cd-pipeline-builderCI pipelines can spin up worktrees for parallel test matrix executionPipeline config triggers setup-worktree.sh per matrix job; port allocation prevents service collisions
release-managerRelease branches get dedicated worktrees for stabilization while feature work continuesRelease worktree is created from the release branch; merged status drives cleanup automation
monorepo-navigatorIn monorepo setups, worktrees must respect package boundaries and shared dependenciesWorktree creation inherits the monorepo root lockfile; package-level dev servers use allocated port blocks
pr-review-expertPR reviews can be performed in isolated worktrees with running code for manual validationReviewer creates a worktree at the PR branch, runs the dev server on allocated ports, and removes after review
tech-debt-trackerStale worktrees and abandoned branches surface as tech debt indicatorsCleanup script output feeds into debt tracking; worktree age and merge status inform priority scores

平台分布

Codex

34.66%
按下载量换算141

Claude

29.31%
按下载量换算120

Cursor

19.99%
按下载量换算82

Gemini CLI

8.48%
按下载量换算35

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/borghei/claude-skills --skill git-worktree-manager 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills