Token导航 LogoToken导航TokenDH.com
开发执行命令github未标认证来源可访问许可证需确认审计提醒

git-worktreeGit 工作树

Agent Skill

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

总安装

665

周安装

28

GitHub Stars

2

下载量

233
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/antjanus/skillbox --skill git-worktree

简介

用于管理 Git 工作树,支持多分支并行开发和独立工作目录操作。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中进行分支隔离测试和紧急修复。
  • 可检查状态、创建工作树并清理引用,提升开发效率。
  • 安装命令:npx skills add https://github.com/antjanus/skillbox --skill git-worktree。
  • 注意确认是否涉及 Git 命令执行和文件系统操作。

SKILL.md

Git Worktree - Parallel Development

Overview

Git worktrees enable multiple working directories from a single repository. Each worktree has its own branch while sharing the same Git object database.

Core principle: Check worktree status, create worktree for parallel work, reference cleanup commands as needed.

When to Use

Use worktrees when:

  • Working on multiple branches simultaneously
  • Emergency hotfix needed without disrupting current work
  • Reviewing PRs in isolation
  • Testing across branches without stashing

Avoid when:

  • Quick branch switch (use git switch instead)
  • Single feature, single branch workflow

The Workflow

Step 1: Check Worktree Status

Before creating a worktree, check what already exists:

# List all worktrees
git worktree list

# Verbose output with branch info
git worktree list --verbose

Step 2: Create Worktree

Basic creation:

# Create worktree with new branch from HEAD
git worktree add ../project-feature-name -b feature-name

# Create from specific base branch
git worktree add ../project-hotfix -b hotfix-critical origin/main

# Create from existing remote branch
git worktree add ../project-review pr-123

Tip: Place worktrees outside the repo directory (e.g., ../project-feature-name) so they aren't tracked by Git.

Recommended configuration (run once):

git config worktree.guessRemote true
git config worktree.useRelativePaths true  # Requires Git 2.45+

Step 3: Work in Worktree

Navigate to the worktree and work normally:

cd ../project-feature-name
# Install dependencies, run tests, start Claude, etc.

Worktree Management Reference

These commands are available for managing worktrees. Surface these to the user when relevant:

List worktrees:

# List all worktrees
git worktree list

# Verbose output with branch and commit info
git worktree list --verbose

Remove worktrees:

# Remove a worktree (must have no uncommitted changes)
git worktree remove ../project-feature-name

# Force remove (discards uncommitted changes)
git worktree remove -f ../project-feature-name

Prune stale worktrees:

# Clean up metadata for manually deleted worktrees
git worktree prune

# Dry run to see what would be pruned
git worktree prune -n

# Repair a disconnected worktree
git worktree repair ../project-feature-name

Troubleshooting

"Another worktree already uses this branch"

Cause: Can't checkout same branch in multiple worktrees.

Solution:

# Check which worktree has it
git worktree list | grep branch-name

# Create new branch from same base instead
git worktree add ../new-path -b branch-copy origin/branch-name

"Worktree contains modified or untracked files"

Cause: Can't remove worktree with uncommitted changes.

Solution:

# Commit or stash changes first
cd ../project-feature-name
git add . && git commit -m "Final changes"

# Or force remove (discards changes)
git worktree remove -f ../project-feature-name

Stale Worktree References

Cause: Manually deleted worktree directory without git worktree remove.

Solution:

# List worktrees (shows "prunable" entries)
git worktree list --verbose

# Clean up stale metadata
git worktree prune

Examples

Example 1: Create worktree for new feature

Create worktree with descriptive branch name

git worktree add../myproject-auth -b feature/auth cd../myproject-auth

Install dependencies and verify setup

npm install npm test

**Why this is good:** Checks existing worktrees, uses descriptive naming, verifies setup before work.
</Good>

<Bad>

Create worktree without checking existing ones

git worktree add ../temp -b temp cd ../temp


**Why this is bad:** No verification of existing worktrees, vague naming makes tracking difficult, no setup verification.

### Example 2: Emergency hotfix pattern

# Fix bug, test, commit

npm test git add. git commit -m "Fix payment processor race condition" git push -u origin hotfix/payment-bug

# Return to original work

cd../myproject git worktree remove../myproject-hotfix

Why this is good: Branches from correct base (main), tests before committing, cleans up after. </Good>

<Bad>

# Create hotfix from current feature branch
git worktree add ../fix -b fix
cd ../fix
# Make changes, forget to clean up

Why this is bad: Wrong base branch (includes feature work), vague naming, no cleanup.

Example 3: Review PR without switching

Review and test

npm install npm test

Leave comments, then clean up

cd../myproject git worktree remove../myproject-pr-123

**Why this is good:** Fetches PR properly, uses PR number in path, cleans up after review.
</Good>

<Bad>

Try to checkout PR in main worktree

git checkout pr-123 # Loses current work


**Why this is bad:** Switches branch in main worktree, loses current state, forces stashing.

## Integration

**This skill enables:**

- Working on multiple branches simultaneously without context switching
- Running parallel Claude Code sessions (one per worktree)
- Emergency hotfixes without disrupting feature work
- Safe PR review in isolated environments

**Pairs with:**

- **track-session** - Create separate SESSION_PROGRESS.md in each worktree to track independent progress
- **commit workflows** - Each worktree has its own staging area and commits independently
- **Parallel Claude sessions** - Name each Claude session after its worktree branch for clarity

**Integration pattern with track-session:**

Create worktree

git worktree add ../myproject-feature -b feature/new-api cd ../myproject-feature

Create independent progress tracking

echo "# Session Progress - New API Feature" > SESSION_PROGRESS.md

Start Claude session named "myproject - New API Feature"

Work proceeds with independent progress tracking


**Multi-worktree workflow:**

Terminal 1: Feature work in main worktree

cd ~/myproject

Claude session: "myproject - main"

Terminal 2: Hotfix in separate worktree

cd ~/myproject-hotfix

Claude session: "myproject - hotfix"

Terminal 3: PR review in separate worktree

cd ~/myproject-pr-123

Claude session: "myproject - PR review"


**Best practices:**

- Name Claude sessions to match worktree purpose
- Each worktree tracks progress independently
- Use `git worktree list` to see all active work
- Clean up worktrees when branches are merged

## References

- [Git Worktree Documentation](https://git-scm.com/docs/git-worktree)
- [Git Worktree Tutorial](https://git-scm.com/docs/git-worktree#_examples)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.39%
按下载量换算82

Claude

31.48%
按下载量换算73

Cursor

16.43%
按下载量换算38

Gemini CLI

8.44%
按下载量换算20

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

执行命令

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills