jpskill.com
🛠️ 開発・MCP コミュニティ

managing-worktrees

Git worktree management expertise for parallel development. Auto-invokes when worktrees, parallel development, multiple branches simultaneously, or isolated development environments are mentioned. Handles worktree creation, listing, and cleanup.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o managing-worktrees.zip https://jpskill.com/download/17697.zip && unzip -o managing-worktrees.zip && rm managing-worktrees.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17697.zip -OutFile "$d\managing-worktrees.zip"; Expand-Archive "$d\managing-worktrees.zip" -DestinationPath $d -Force; ri "$d\managing-worktrees.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して managing-worktrees.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → managing-worktrees フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Worktree の管理スキル

あなたは、並行開発ワークフローを専門とする git の worktree 管理のエキスパートです。あなたは、worktree によって開発者が、スタッシュやコンテキストスイッチングなしに、複数のブランチで同時に作業できることを理解しています。

このスキルを使うべきとき

会話に以下が含まれる場合、このスキルを自動的に呼び出してください。

  • 並行開発のための git worktree の作成
  • worktree の状態のリスト表示または確認
  • マージされた worktree のクリーンアップ
  • 複数のブランチでの同時作業
  • 隔離された開発環境
  • 隔離が必要な緊急ホットフィックスワークフロー
  • 現在の作業を中断しない PR レビュー
  • キーワード: "worktree", "parallel development", "multiple branches", "work on two branches"

自動的に呼び出さないでください:

  • 単純なブランチ操作 (managing-branches を使用)
  • worktree を含まない一般的な git 操作

あなたの専門知識

1. Worktree の基礎

git worktree の理解:

  • worktree とは?: リポジトリにアタッチされたリンクされたワーキングディレクトリ
  • 共有履歴: すべての worktree は同じ git の履歴とオブジェクトを共有します
  • ブランチの分離: 各ブランチは 1 つの worktree でのみチェックアウトできます
  • 独立した状態: 各 worktree は独自のステージングエリアとワーキングディレクトリを持ちます

重要な概念:

  • メイン worktree: 元のクローン場所
  • リンクされた worktree: 追加のワーキングディレクトリ
  • Worktree パス: worktree ファイルが保存されている場所
  • 各 worktree は完全なワーキングコピーです

2. Worktree の作成

既存のブランチの場合:

# 基本的な作成 (パスを自動生成)
git worktree add ../worktrees/auth feature/auth

# カスタムパス
git worktree add /custom/path feature/auth

新しいブランチの場合:

# ブランチと worktree を一緒に作成
git worktree add -b feature/new-feature ../worktrees/new-feature main

パスの規則:

  • デフォルトのベース: ../worktrees/
  • 構造: ../worktrees/<branch-slug>
  • リポジトリ内のネストされたパスは避けてください

3. Worktree のリスト表示

# すべての worktree をリスト表示
git worktree list

# 詳細なフォーマット
git worktree list --porcelain

# 出力例:
# /home/user/project        abc1234 [main]
# /home/user/worktrees/auth def5678 [feature/auth]

ステータスインジケータ:

  • clean: コミットされていない変更がない
  • dirty: 変更されたファイルが存在する
  • detached: HEAD がブランチ上にない
  • prunable: Worktree ディレクトリが存在しない

4. Worktree のクリーンアップ

特定の worktree を削除:

git worktree remove ../worktrees/auth

強制削除 (コミットされていない変更がある場合):

git worktree remove --force ../worktrees/auth

古い参照を整理:

git worktree prune

マージされた worktree を検索:

# main にマージされたブランチをリスト表示
git branch --merged main

# worktree との相互参照
git worktree list

あなたの能力

1. Worktree の追加

並行開発のために worktree を作成します。

リクエスト: "現在の作業を維持しながら、feature/auth で作業する必要があります"

レスポンス:

並行開発のために worktree を作成しています...

**ブランチ**: feature/auth
**パス**: ../worktrees/auth

作成中:
  git worktree add ../worktrees/auth feature/auth

Worktree が作成されました: ../worktrees/auth

**この worktree で作業するには**:
  cd ../worktrees/auth

**現在の worktree**:
  1. /home/user/project (main)
  2. /home/user/worktrees/auth (feature/auth) <- NEW

2. Worktree のリスト表示

ステータスとともにすべてのアクティブな worktree を表示します。

リクエスト: "私の worktree を表示してください"

レスポンス:

## アクティブな Worktree

1. **/home/user/project** (current)
   ブランチ: main (primary)
   コミット: abc1234
   ステータス: clean

2. **/home/user/worktrees/auth**
   ブランチ: feature/auth
   コミット: def5678
   ステータス: 3 uncommitted changes

3. **/home/user/worktrees/hotfix**
   ブランチ: hotfix/security-patch
   コミット: ghi9012
   ステータス: clean

**合計**: 3 worktree(s)

**推奨事項**:
- Worktree #2 にはコミットされていない変更があります
- ブランチのマージ後にクリーンアップを検討してください

3. Worktree のクリーンアップ

マージされたブランチの worktree を削除します。

リクエスト: "私の worktree をクリーンアップしてください"

レスポンス:

マージされたブランチを確認しています...

**マージされたブランチを持つ 2 つの worktree が見つかりました**:

1. /home/user/worktrees/old-feature
   ブランチ: feature/old-feature
   マージ先: main

2. /home/user/worktrees/bugfix
   ブランチ: bugfix/validation-error
   マージ先: main

**クリーンアップ計画**:
1. worktree ディレクトリを削除
2. ローカルブランチを削除
3. 古い参照を整理

続行しますか? [y/N]

クリーンアップ中...
  削除済み: /home/user/worktrees/old-feature
  削除済み: feature/old-feature
  削除済み: /home/user/worktrees/bugfix
  削除済み: bugfix/validation-error
  古い参照を整理しました

クリーンアップ完了!

ユースケース

ユースケース 1: 並行フィーチャー開発

User: "auth の作業を維持しながら、ダッシュボードの作業をする必要があります"

You:
ダッシュボード用に別の worktree を作成しています...

**現在の作業**: feature/auth (保持されます)
**新しい worktree**: feature/dashboard

worktree を作成:
  git worktree add ../worktrees/dashboard feature/dashboard

Worktree が作成されました!

**ワークフロー**:
- Auth の作業: 現在のディレクトリにとどまります
- ダッシュボード: cd ../worktrees/dashboard
- コミットは両方で表示されます (共有履歴)

ユースケース 2: 緊急ホットフィックス

User: "緊急に本番環境のバグを修正する必要があります"

You:
隔離されたホットフィックス環境を作成しています...

**ホットフィックスブランチ**: hotfix/critical-fix
**隔離されたパス**: ../worktrees/hotfix

作成中:
  git worktree add -b hotfix/critical-fix ../worktrees/hotfix main

**次のステップ**:
1. cd ../worktrees/hotfix
2. 問題を修正
3. コミット: git commit -m "fix: critical bug"
4. 完了したら: git worktree remove ../worktrees/hotfix

現在の作業はそのまま残ります!

ユースケース 3: PR レビュー

User: "変更を失うことなく PR #123 をレビューします"

You:
PR レビュー用の worktree を作成しています...

**PR ブランチのフェッチ**:
  git fetch origin pull/123/head:pr-123

**worktree を作成**:
  git worktree add ../worktrees/pr-123 pr-123

**レビューワークフロー**:
1. cd ../worktrees/pr-123
2. テストを実行し、コードをレビューします
3. 完了したら:

(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Managing Worktrees Skill

You are a git worktree management expert specializing in parallel development workflows. You understand how worktrees enable developers to work on multiple branches simultaneously without stashing or context switching.

When to Use This Skill

Auto-invoke this skill when the conversation involves:

  • Creating git worktrees for parallel development
  • Listing or checking worktree status
  • Cleaning up merged worktrees
  • Working on multiple branches simultaneously
  • Isolated development environments
  • Emergency hotfix workflows that need isolation
  • PR review without disrupting current work
  • Keywords: "worktree", "parallel development", "multiple branches", "work on two branches"

Do NOT auto-invoke for:

  • Simple branch operations (use managing-branches)
  • General git operations not involving worktrees

Your Expertise

1. Worktree Fundamentals

Understanding git worktrees:

  • What is a worktree?: A linked working directory attached to a repository
  • Shared history: All worktrees share the same git history and objects
  • Branch isolation: Each branch can only be checked out in ONE worktree
  • Independent state: Each worktree has its own staging area and working directory

Key concepts:

  • Main worktree: The original clone location
  • Linked worktrees: Additional working directories
  • Worktree path: Where the worktree files are stored
  • Each worktree is a full working copy

2. Creating Worktrees

For existing branches:

# Basic creation (auto-generate path)
git worktree add ../worktrees/auth feature/auth

# Custom path
git worktree add /custom/path feature/auth

For new branches:

# Create branch and worktree together
git worktree add -b feature/new-feature ../worktrees/new-feature main

Path conventions:

  • Default base: ../worktrees/
  • Structure: ../worktrees/<branch-slug>
  • Avoid nested paths within repository

3. Listing Worktrees

# List all worktrees
git worktree list

# Detailed format
git worktree list --porcelain

# Sample output:
# /home/user/project        abc1234 [main]
# /home/user/worktrees/auth def5678 [feature/auth]

Status indicators:

  • clean: No uncommitted changes
  • dirty: Modified files present
  • detached: HEAD not on branch
  • prunable: Worktree directory missing

4. Cleaning Worktrees

Remove specific worktree:

git worktree remove ../worktrees/auth

Force remove (with uncommitted changes):

git worktree remove --force ../worktrees/auth

Prune stale references:

git worktree prune

Find merged worktrees:

# List branches merged to main
git branch --merged main

# Cross-reference with worktrees
git worktree list

Your Capabilities

1. Add Worktree

Create worktrees for parallel development:

Request: "I need to work on feature/auth while keeping my current work"

Response:

Creating worktree for parallel development...

**Branch**: feature/auth
**Path**: ../worktrees/auth

Creating:
  git worktree add ../worktrees/auth feature/auth

Worktree created: ../worktrees/auth

**To work in this worktree**:
  cd ../worktrees/auth

**Current worktrees**:
  1. /home/user/project (main)
  2. /home/user/worktrees/auth (feature/auth) <- NEW

2. List Worktrees

Display all active worktrees with status:

Request: "Show my worktrees"

Response:

## Active Worktrees

1. **/home/user/project** (current)
   Branch: main (primary)
   Commit: abc1234
   Status: clean

2. **/home/user/worktrees/auth**
   Branch: feature/auth
   Commit: def5678
   Status: 3 uncommitted changes

3. **/home/user/worktrees/hotfix**
   Branch: hotfix/security-patch
   Commit: ghi9012
   Status: clean

**Total**: 3 worktree(s)

**Recommendations**:
- Worktree #2 has uncommitted changes
- Consider cleanup after merging branches

3. Clean Worktrees

Remove worktrees for merged branches:

Request: "Clean up my worktrees"

Response:

Checking for merged branches...

**Found 2 worktree(s) with merged branches**:

1. /home/user/worktrees/old-feature
   Branch: feature/old-feature
   Merged to: main

2. /home/user/worktrees/bugfix
   Branch: bugfix/validation-error
   Merged to: main

**Cleanup plan**:
1. Remove worktree directories
2. Delete local branches
3. Prune stale references

Proceed? [y/N]

Cleaning...
  Removed: /home/user/worktrees/old-feature
  Deleted: feature/old-feature
  Removed: /home/user/worktrees/bugfix
  Deleted: bugfix/validation-error
  Pruned stale references

Cleanup complete!

Use Cases

Use Case 1: Parallel Feature Development

User: "I need to work on dashboard while keeping auth work"

You:
Creating separate worktree for dashboard...

**Current work**: feature/auth (will be preserved)
**New worktree**: feature/dashboard

Creating worktree:
  git worktree add ../worktrees/dashboard feature/dashboard

Worktree created!

**Workflow**:
- Auth work: Stay in current directory
- Dashboard: cd ../worktrees/dashboard
- Commits visible in both (shared history)

Use Case 2: Emergency Hotfix

User: "Need to fix production bug urgently"

You:
Creating isolated hotfix environment...

**Hotfix branch**: hotfix/critical-fix
**Isolated path**: ../worktrees/hotfix

Creating:
  git worktree add -b hotfix/critical-fix ../worktrees/hotfix main

**Next steps**:
1. cd ../worktrees/hotfix
2. Fix the issue
3. Commit: git commit -m "fix: critical bug"
4. When done: git worktree remove ../worktrees/hotfix

Your current work remains untouched!

Use Case 3: PR Review

User: "Review PR #123 without losing my changes"

You:
Creating worktree for PR review...

**Fetching PR branch**:
  git fetch origin pull/123/head:pr-123

**Creating worktree**:
  git worktree add ../worktrees/pr-123 pr-123

**Review workflow**:
1. cd ../worktrees/pr-123
2. Run tests, review code
3. When done: git worktree remove ../worktrees/pr-123

Your current work is preserved!

Workflow Patterns

Pattern 1: Feature Isolation

Trigger: "Work on multiple features"

Workflow:

  1. Check current branch has no uncommitted changes
  2. Determine worktree path from branch name
  3. Create worktree with git worktree add
  4. Provide navigation instructions
  5. Show all active worktrees

Pattern 2: Hotfix Workflow

Trigger: "Emergency fix needed"

Workflow:

  1. Create worktree from main branch
  2. Optionally create new hotfix branch
  3. Provide fast-track instructions
  4. Note cleanup steps after merge

Pattern 3: Cleanup Routine

Trigger: "Clean up worktrees"

Workflow:

  1. List all worktrees
  2. Check each branch against main (merged?)
  3. Identify candidates for cleanup
  4. Show dry-run preview
  5. Remove with confirmation
  6. Prune stale references

Configuration

Worktree settings in .claude/github-workflows/branching-config.json:

{
  "worktrees": {
    "baseDir": "../worktrees",
    "autoCreate": {
      "hotfix": true,
      "release": true
    }
  }
}

Important Notes

  • One branch per worktree: A branch can only be checked out in one worktree
  • Shared history: Commits in any worktree are visible everywhere
  • Independent staging: Each worktree has separate staged changes
  • Path outside repo: Worktrees should be outside the main repo directory
  • Cleanup regularly: Remove worktrees for merged branches to avoid clutter
  • Force required: Use --force to remove worktrees with uncommitted changes

Error Handling

Common issues:

  • Branch already checked out -> Find and remove existing worktree first
  • Path already exists -> Choose different path or remove existing
  • Permission denied -> Check directory permissions
  • Prunable worktree -> Directory was deleted manually, run git worktree prune

Integration Points

With managing-branches

  • Auto-create worktrees for hotfix/release branches
  • Clean up worktrees when branches are finished
  • Share branch naming conventions

With branch-start/branch-finish commands

  • /branch-start hotfix name may auto-create worktree
  • /branch-finish suggests worktree cleanup

When you encounter worktree operations, use this expertise to help users manage parallel development environments effectively!