Token导航 LogoToken导航

Agent Skill · 运维和基础设施

git-worktrees(Git 工作树)

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

git-worktrees 是运维和基础设施类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证为 MIT,第三方扫描已通过,按安装量在运维和基础设施类的 2,449 个 Skill 里排第 738。

总安装 1,836周安装 75GitHub Stars 126下载 588核验 2026-05-01

安装说明

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

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/jamesrochabrun/skills --skill git-worktrees

这个 Skill 是做什么的

运维和基础设施类 Skill 处理部署、监控、日志和云资源,多数需要较高的执行权限。

Git 工作树支持使用 Claude Code 进行真正的并行开发: ✅ 运行多个 Claude 会话而不发生冲突 ✅ 立即切换上下文,无需隐藏 ✅ 安全实验而不破坏主要功能 ✅ 简单的脚本处理所有复杂性 ✅ 常见场景的简洁工作流程 开始使用: 脚本/create_worktree.sh 就是这样!

这些脚本使工作树变得简单实用。每周安装量 75 存储库 詹姆斯罗查布伦/技能 GitHub 之星 126 第一次看到 4 天前 安全审计 Gen Agent Trust Hub 通行证 套接字通行证 斯尼克通行证

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

上手步骤

4 步
  1. 1

    确认自己的宿主工具

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

  2. 2

    拿到安装命令

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

  3. 3

    安装后重启宿主

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

  4. 4

    按最小权限试用

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

常见问题

6 条

git-worktrees 怎么安装?

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

git-worktrees 支持哪些 AI 工具?

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

git-worktrees 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

git-worktrees 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

git-worktrees 用的人多吗?

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

git-worktrees 安全吗?

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

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

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理运维和基础设施类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

运维和基础设施类 Skill 对比

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

头脑风暴 · Codex、Claude

3,148,776173,131操作浏览器MIT通过
copywriting

文案写作 · Codex、Claude

1,996,72425,583需要联网MIT通过
openclaw-secure-linux-cloud

OpenClaw secure linux cloud 命令行 · Codex、Claude

1,853,08840接触敏感数据未明确未通过
xget

xget 命令行 · Codex、Claude

1,799,28040执行命令未明确未通过
requesting-code-review

代码审查请求 · Codex、Claude

1,590,144173,103权限未标注MIT通过
git-worktrees

Git 工作树 · 本页

1,836126需要联网MIT通过

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

SKILL.md 原文

Git Worktrees for Claude Code

Overview

Run multiple Claude Code sessions in parallel on different branches using Git worktrees. This skill provides simple scripts and workflows to set up, manage, and clean up worktrees, enabling true parallel development without conflicts.

Why Worktrees?

  • Parallel Development: Run multiple Claude Code instances simultaneously
  • Zero Conflicts: Each worktree has independent file state
  • Fast Context Switching: No need to stash/commit when switching tasks
  • Isolated Experiments: Try different approaches without affecting main work
  • Long-Running Tasks: Let Claude work in background while you continue in main

Quick Start

1. Create a New Worktree (Super Easy!)

Just run the interactive script:

scripts/create_worktree.sh

This will:

  • ✅ Prompt for feature name
  • ✅ Create a new branch
  • ✅ Set up the worktree
  • ✅ Open in VS Code / editor
  • ✅ Give you the Claude Code setup command

That's it! The script handles all complexity.


2. View All Worktrees

scripts/list_worktrees.sh

Shows a clean, formatted list of all your worktrees with their branches and status.


3. Clean Up Old Worktrees

scripts/cleanup_worktrees.sh

Interactive removal of merged or abandoned worktrees.


Core Workflow

Pattern 1: Parallel Feature Development

Scenario: You want Claude to build feature A while you work on feature B.

Steps:

  1. Create worktree for feature A: scripts/create_worktree.sh # Enter: feature-a # Script creates:../repo-feature-a/
  2. Open Claude Code in the new worktree:

- The script outputs the path - Open Claude Code and navigate to that directory - Run /init to orient Claude

  1. Give Claude the task: "Build the user authentication feature with OAuth support"
  2. Continue your work in main:

- Your original directory is unchanged - No conflicts, no waiting - Claude works in parallel

  1. When both are done, merge: # Review Claude's work cd../repo-feature-a git log # If good, merge back git checkout main git merge feature-a # Clean up scripts/cleanup_worktrees.sh

Pattern 2: Long-Running Refactor

Scenario: You want Claude to refactor a large module while you continue development.

Steps:

  1. Create refactor worktree: scripts/create_worktree.sh # Enter: refactor-auth-module
  2. Start Claude in refactor worktree: "Refactor the authentication module to use dependency injection"
  3. Continue your daily work in main:

- No interruption - No merge conflicts - Check progress periodically

  1. Review and integrate when ready: cd../repo-refactor-auth-module git log --oneline # Review changes # Merge when satisfied git checkout main git merge refactor-auth-module

Pattern 3: Multiple AI Agents (Advanced)

Scenario: You want 3 Claude instances working on different features simultaneously.

Steps:

  1. Create 3 worktrees: scripts/create_worktree.sh # feature-api-endpoints scripts/create_worktree.sh # feature-ui-dashboard scripts/create_worktree.sh # feature-email-notifications
  2. Open 3 Claude Code sessions:

- Session 1: ../repo-feature-api-endpoints/ - Session 2: ../repo-feature-ui-dashboard/ - Session 3: ../repo-feature-email-notifications/

  1. Assign tasks to each Claude:

- Claude 1: "Build REST API endpoints for user management" - Claude 2: "Create admin dashboard UI" - Claude 3: "Implement email notification system"

  1. Monitor progress: scripts/list_worktrees.sh
  2. Merge features as they complete: # Feature by feature git checkout main git merge feature-api-endpoints git merge feature-ui-dashboard git merge feature-email-notifications # Clean up scripts/cleanup_worktrees.sh

Pattern 4: Hotfix While Development Continues

Scenario: Production bug needs immediate fix while Claude is working on a feature.

Steps:

  1. Claude is already working in a feature worktree

- Let it continue, don't interrupt

  1. Create hotfix worktree from main: scripts/create_worktree.sh # Enter: hotfix-login-bug # Choose base branch: main
  2. Fix the bug yourself or with another Claude session: cd../repo-hotfix-login-bug # Make fixes git add. git commit -m "Fix login redirect bug"
  3. Merge hotfix to main: git checkout main git merge hotfix-login-bug git push origin main
  4. Sync feature worktree with latest main: cd../repo-feature-xyz scripts/sync_worktree.sh # Merges latest main into feature branch

Essential Scripts

scripts/create_worktree.sh

Interactive worktree creation with all the right defaults.

What it does:

  1. Prompts for feature name
  2. Validates git repo
  3. Creates branch from main (or specified base)
  4. Sets up worktree in parallel directory
  5. Outputs setup instructions

Usage:

scripts/create_worktree.sh

# Prompts:
# Feature name: my-feature
# Base branch (default: main):
#
# Creates: ../repo-my-feature/
# Branch: my-feature

Advanced usage:

# Create from specific branch
scripts/create_worktree.sh --base develop

# Specify location
scripts/create_worktree.sh --dir ~/worktrees/my-feature

scripts/list_worktrees.sh

Shows all active worktrees with status.

Output:

╔════════════════════════════════════════════════╗
║            Active Git Worktrees                ║
╚════════════════════════════════════════════════╝

📁 Main Worktree
   Path: /home/user/project
   Branch: main
   Status: clean

📁 Feature Worktrees
   Path: /home/user/project-feature-api
   Branch: feature-api
   Status: 2 uncommitted changes

   Path: /home/user/project-refactor
   Branch: refactor-auth
   Status: clean

scripts/cleanup_worktrees.sh

Interactive cleanup of old worktrees.

Features:

  • Lists all worktrees with merge status
  • Identifies merged branches (safe to remove)
  • Prompts for confirmation
  • Safely removes worktree and branch

Usage:

scripts/cleanup_worktrees.sh

# Output:
# Found 3 worktrees
#
# 1. feature-api (merged to main) - Safe to remove
# 2. feature-dashboard (not merged) - Keep
# 3. old-experiment (not merged, 30 days old) - Consider removing
#
# Which worktrees to remove? (1,3): 1

scripts/sync_worktree.sh

Keep worktree up-to-date with main branch.

What it does:

  1. Fetches latest from remote
  2. Merges main into current worktree branch
  3. Handles conflicts with guidance

Usage:

# From within a worktree
cd ../repo-feature-api
scripts/sync_worktree.sh

# Or specify worktree
scripts/sync_worktree.sh ../repo-feature-api

Claude Code Integration

Important: Run /init in Each Worktree

When you open a new Claude Code session in a worktree, always run /init first:

/init

This ensures Claude:

  • Understands the codebase structure
  • Has proper context
  • Can navigate files correctly

Recommended Claude Code Workflow

  1. Create worktree (using script)
  2. Open Claude Code in worktree directory
  3. Run /init to orient Claude
  4. Give task to Claude
  5. Monitor via git log or file watching
  6. Review when complete
  7. Merge if satisfied
  8. Cleanup worktree

Best Practices

Naming Conventions

Good names:

  • feature-user-auth ✅
  • refactor-api-layer ✅
  • hotfix-login-bug ✅
  • experiment-new-db ✅

Bad names:

  • test ❌ (too vague)
  • wt1 ❌ (meaningless)
  • fixes ❌ (unclear)

Recommended format:

<type>-<short-description>

Types:
- feature-*
- refactor-*
- hotfix-*
- experiment-*
- review-*

Directory Structure

Recommended layout:

~/projects/
  └── myapp/              # Main worktree (main branch)
      ├── myapp-feature-api/      # Feature worktree
      ├── myapp-refactor-auth/    # Refactor worktree
      └── myapp-hotfix-bug/       # Hotfix worktree

The scripts default to creating worktrees as siblings to your main directory with a naming pattern: <repo>-<branch-name>.


When to Use Worktrees

✅ Use worktrees when:

  • Running multiple Claude Code sessions in parallel
  • Working on independent features simultaneously
  • Doing long-running refactors
  • Experimenting with major changes
  • Quick hotfixes during feature development
  • Code reviews without interrupting work

❌ Don't use worktrees for:

  • Simple branch switching (just use git checkout)
  • Minor tweaks (stash instead)
  • Single-task workflows
  • Very short-lived branches (< 1 hour)

Keeping Worktrees in Sync

Problem: Feature branches can get out of date with main.

Solution: Regularly sync worktrees:

# Option 1: Use the sync script
cd ../repo-feature-api
scripts/sync_worktree.sh

# Option 2: Manual sync
cd ../repo-feature-api
git fetch origin
git merge origin/main

Recommended frequency:

  • Daily for long-running features
  • After major merges to main
  • Before creating PRs

Managing Many Worktrees

Quick status of all worktrees:

scripts/list_worktrees.sh

Regular cleanup (weekly):

scripts/cleanup_worktrees.sh

Find stale worktrees:

# Worktrees with old commits
git worktree list | while read path branch commit; do
  cd "$path"
  last_commit=$(git log -1 --format=%cr)
  echo "$branch: Last commit $last_commit"
done

Troubleshooting

Issue: "fatal: invalid reference"

Cause: Branch name has invalid characters

Solution: Use alphanumeric + hyphens only:

# Bad
feature/my_feature  ❌

# Good
feature-my-feature  ✅

Issue: "cannot remove worktree, path is not a working tree"

Cause: Worktree directory was manually deleted

Solution: Prune worktree references:

git worktree prune

Issue: Claude seems "lost" in worktree

Cause: Didn't run /init after opening worktree

Solution: Always run /init when starting Claude in a new worktree:

/init

Issue: Merge conflicts when syncing worktree

Cause: Changes in worktree conflict with main

Solution 1: Resolve conflicts manually:

cd ../repo-feature-api
git fetch origin
git merge origin/main
# Fix conflicts in editor
git add .
git commit -m "Merge main and resolve conflicts"

Solution 2: If you want to discard worktree changes and restart:

cd ../repo-feature-api
git fetch origin
git reset --hard origin/main
# Start feature over

Issue: "Cannot lock ref" error

Cause: Branch exists in multiple worktrees

Solution: You can't have the same branch checked out in multiple worktrees. Create a new branch:

scripts/create_worktree.sh
# Use a different branch name

Issue: Worktree takes up too much disk space

Cause: Git worktrees share the .git directory, but files are duplicated

Solution 1: Clean up old worktrees:

scripts/cleanup_worktrees.sh

Solution 2: For large repos, use sparse-checkout:

git -C ../repo-feature-api sparse-checkout set src/ tests/

Advanced Usage

Custom Slash Command

Create a /worktree command for Claude Code. See references/slash_command_template.md for the complete setup.

Usage after setup:

/worktree feature-new-api

Claude will:

  1. Create the worktree
  2. Provide setup instructions
  3. Offer to continue the conversation in the new worktree

Sharing Worktrees in Team

Worktrees are local only, but you can share the workflow:

  1. Share branch, not worktree: cd../repo-feature-api git push origin feature-api # Teammate creates their own worktree git worktree add../repo-feature-api feature-api
  2. Document your worktree structure in team docs
  3. Use consistent naming across team

Worktree Performance Optimization

For large repos:

  1. Use sparse-checkout (only checkout files you need): git -C../repo-feature-api sparse-checkout init git -C../repo-feature-api sparse-checkout set src/ tests/
  2. Use worktree prune regularly: git worktree prune
  3. Limit concurrent worktrees to 3-5 for best performance

Common Workflows Summary

Quick Reference

TaskCommand
Create new worktreescripts/create_worktree.sh
List all worktreesscripts/list_worktrees.sh
Clean up worktreesscripts/cleanup_worktrees.sh
Sync with mainscripts/sync_worktree.sh
Manual creategit worktree add../path branch-name
Manual listgit worktree list
Manual removegit worktree remove../path
Prune referencesgit worktree prune

Real-World Examples

Example 1: Parallel API & UI Development

Setup:

# Create API worktree
scripts/create_worktree.sh
# Name: feature-api

# Create UI worktree
scripts/create_worktree.sh
# Name: feature-ui

Execution:

  • Claude 1 in ../repo-feature-api: "Build REST API for user management"
  • Claude 2 in ../repo-feature-ui: "Create React UI for user management"
  • You in main: Continue other work

Merge:

git checkout main
git merge feature-api
git merge feature-ui
scripts/cleanup_worktrees.sh

Example 2: Code Review Without Context Switching

Scenario: Need to review PR while Claude works on feature

Setup:

# Claude is working in feature worktree
# You need to review PR #123

scripts/create_worktree.sh
# Name: review-pr-123
# Base: pr-branch-name

Execution:

  • Review code in ../repo-review-pr-123
  • Claude continues work in ../repo-feature-xyz
  • No context switching needed

Cleanup:

# After review
scripts/cleanup_worktrees.sh
# Select review-pr-123

Example 3: Experimentation Without Risk

Scenario: Want to try a radical refactor without breaking current work

Setup:

scripts/create_worktree.sh
# Name: experiment-new-architecture

Execution:

  • Experiment freely in ../repo-experiment-new-architecture
  • Main worktree remains stable
  • If experiment fails, just delete worktree

Decision:

# If experiment succeeded
git checkout main
git merge experiment-new-architecture

# If experiment failed
scripts/cleanup_worktrees.sh
# Delete experiment worktree (no harm done)

Tips for Maximum Productivity

1. Name Worktrees Descriptively

  • You'll thank yourself later when you have 5 worktrees open

2. Always Run /init

  • First thing when opening Claude in a new worktree

3. Merge Frequently

  • Don't let worktrees diverge for weeks
  • Sync with main regularly

4. Clean Up Weekly

  • Run scripts/cleanup_worktrees.sh every Friday
  • Keep your workspace tidy

5. Use Scripts

  • Don't memorize git worktree commands
  • Scripts handle edge cases and validation

6. Monitor Progress

  • Use scripts/list_worktrees.sh to see what's active
  • Check git logs in worktrees periodically

7. Limit Concurrent Sessions

  • 3-5 worktrees max for best performance
  • More than that gets hard to manage

Resources

Scripts

  • create_worktree.sh - Interactive worktree creation
  • list_worktrees.sh - Show all active worktrees
  • cleanup_worktrees.sh - Remove old worktrees
  • sync_worktree.sh - Keep worktrees synchronized

References

  • worktree_commands.md - Complete Git worktree command reference
  • best_practices.md - Detailed best practices and patterns
  • slash_command_template.md - Create custom /worktree command

Summary

Git worktrees enable true parallel development with Claude Code:

✅ Run multiple Claude sessions without conflicts ✅ Switch contexts instantly without stashing ✅ Experiment safely without breaking main ✅ Simple scripts handle all complexity ✅ Clean workflows for common scenarios

Get started:

scripts/create_worktree.sh

That's it! The scripts make worktrees simple and practical.

平台分布

Claude Code

30.74%
按下载量换算181

OpenCode

23.56%
按下载量换算139

windsurf

16%
按下载量换算94

Antigravity

13.77%
按下载量换算81

Cursor

7.57%
按下载量换算45

Gemini CLI

3.22%
按下载量换算19

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills