🛠️ GitWorktreeマネージャー
複数の作業ディレクトリ(ワークツリー)を
📺 まず動画で見る(YouTube)
▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Git Worktree Manager
🇯🇵 日本人クリエイター向け解説
複数の作業ディレクトリ(ワークツリー)を
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o git-worktree-manager.zip https://jpskill.com/download/4861.zip && unzip -o git-worktree-manager.zip && rm git-worktree-manager.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/4861.zip -OutFile "$d\git-worktree-manager.zip"; Expand-Archive "$d\git-worktree-manager.zip" -DestinationPath $d -Force; ri "$d\git-worktree-manager.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
git-worktree-manager.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
git-worktree-managerフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-18
- 同梱ファイル
- 6
💬 こう話しかけるだけ — サンプルプロンプト
- › Git Worktree Manager を使って、最小構成のサンプルコードを示して
- › Git Worktree Manager の主な使い方と注意点を教えて
- › Git Worktree Manager を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[Skill 名] git-worktree-manager
Git Worktree Manager
Tier: POWERFUL
Category: Engineering
Domain: 並行開発とブランチ分離
概要
このスキルは、Git ワークツリーを使用して並行フィーチャー作業を安全に実行するために使用します。各ワークツリーが他のブランチに干渉することなく独立したローカルアプリのように動作するように、ブランチ分離、ポート割り当て、環境同期、およびクリーンアップを標準化します。
このスキルは、各エージェントまたはターミナルセッションが1つのワークツリーを所有するマルチエージェントワークフロー向けに最適化されています。
コア機能
- 決定論的な命名規則で新規または既存のブランチからワークツリーを作成します。
- ワークツリーごとに競合しないポートを自動割り当てし、割り当てを永続化します。
- メインリポジトリから新しいワークツリーにローカル環境ファイル(
.env*)をコピーします。 - ロックファイルの検出に基づいて、オプションで依存関係をインストールします。
- クリーンアップ前に古いワークツリーとコミットされていない変更を検出します。
- マージされたブランチを識別し、古いワークツリーを安全に削除します。
使用する場面
- ローカルで2つ以上のブランチを同時に開く必要がある場合
- フィーチャー、ホットフィックス、PR検証のために分離された開発サーバーが必要な場合
- ブランチを共有してはならない複数のエージェントと作業している場合
- 現在のブランチがブロックされているが、今すぐ迅速な修正をリリースする必要がある場合
- アドホックな
rm -rf操作ではなく、再現可能なクリーンアップが必要な場合
主要なワークフロー
1. 完全に準備されたワークツリーの作成
- ブランチ名とワークツリー名を選択します。
- マネージャースクリプトを実行します(ブランチが存在しない場合は作成します)。
- 生成されたポートマップを確認します。
- 割り当てられたポートを使用してアプリを起動します。
python scripts/worktree_manager.py \
--repo . \
--branch feature/new-auth \
--name wt-auth \
--base-branch main \
--install-deps \
--format text
JSON 自動化入力を使用する場合:
cat config.json | python scripts/worktree_manager.py --format json
# or
python scripts/worktree_manager.py --input config.json --format json
2. 並行セッションの実行
推奨される慣例:
- メインリポジトリ:デフォルトポート上の統合ブランチ(
main/develop) - ワークツリーA:フィーチャーブランチ + オフセットポート
- ワークツリーB:ホットフィックスブランチ + 次のオフセット
各ワークツリーには、割り当てられたポートを含む .worktree-ports.json が含まれています。
3. 安全チェックによるクリーンアップ
- すべてのワークツリーと古い経過時間をスキャンします。
- ダーティなツリーとブランチのマージステータスを検査します。
- マージ済みでクリーンなワークツリーのみを削除するか、明示的に強制します。
python scripts/worktree_cleanup.py --repo . --stale-days 14 --format text
python scripts/worktree_cleanup.py --repo . --remove-merged --format text
4. Docker Compose パターン
割り当てられたポートからマッピングされたワークツリーごとのオーバーライドファイルを使用します。スクリプトは決定論的なポートマップを出力します。それを docker-compose.worktree.yml に適用します。
具体的なテンプレートについては、docker-compose-patterns.md を参照してください。
5. ポート割り当て戦略
デフォルトの戦略は、衝突チェックを伴う base + (index * stride) です。
- アプリ:
3000 - Postgres:
5432 - Redis:
6379 - ストライド:
10
完全な戦略とエッジケースについては、port-allocation-strategy.md を参照してください。
スクリプトインターフェース
python scripts/worktree_manager.py --help- ワークツリーの作成/一覧表示
- ポートの割り当て/永続化
.env*ファイルのコピー- オプションの依存関係のインストール
python scripts/worktree_cleanup.py --help- 経過時間による古い検出
- ダーティ状態の検出
- マージされたブランチの検出
- オプションの安全な削除
両方のツールは、自動化パイプラインのために stdin JSON と --input ファイルモードをサポートしています。
よくある落とし穴
- メインリポジトリディレクトリ内にワークツリーを作成すること
- すべてのブランチで
localhost:3000を再利用すること - 分離されたフィーチャーブランチ間で1つのデータベースURLを共有すること
- コミットされていない変更があるワークツリーを削除すること
- ブランチ削除後に古いメタデータを削除し忘れること
- ターゲットブランチをチェックせずにマージ済みステータスを想定すること
ベストプラクティス
- ワークツリーごとに1つのブランチ、ワークツリーごとに1つのエージェント。
- ワークツリーは短命に保ち、マージ後に削除します。
- 決定論的な命名パターン(
wt-<topic>)を使用します。 - ポートマッピングはメモリやターミナルノートではなく、ファイルに永続化します。
- アクティブなリポジトリでは毎週クリーンアップスキャンを実行します。
- マシンフローには
--format jsonを、人間によるレビューには--format textを使用します。 - 変更が意図的に破棄される場合を除き、ダーティなワークツリーを強制的に削除しないでください。
検証チェックリスト
セットアップ完了を主張する前に:
git worktree listが期待されるパス + ブランチを表示していること。.worktree-ports.jsonが存在し、一意のポートが含まれていること。.envファイルが正常にコピーされていること(ソースリポジトリに存在する場合)。- 依存関係のインストールコマンドがコード
0で終了していること(有効な場合)。 - クリーンアップスキャンが意図しない古いダーティツリーを報告しないこと。
参照
- port-allocation-strategy.md
- docker-compose-patterns.md
- クイックスタートとインストール詳細については README.md を参照してください。
決定マトリックス
新しいワークツリーを作成する前に、このクイックセレクターを使用してください。
- 分離された依存関係とサーバーポートが必要な場合 -> 新しいワークツリーを作成します
- 簡単なローカル差分レビューのみが必要な場合 -> 現在のツリーにとどまります
- フィーチャーブランチがダーティな間にホットフィックスが必要な場合 -> 専用のホットフィックスワークツリーを作成します
- バグトリアージのために一時的な再現ブランチが必要な場合 -> 一時的なワークツリーを作成し、同日中にクリーンアップします
運用チェックリスト
作成前
- メインリポジトリにクリーンなベースラインまたは意図的な WIP コミットがあることを確認します。
- ターゲットブランチの命名規則を確認します。
- 必要なベースブランチ(
main/develop)が存在することを確認します。 - 予約済みのローカルポートが、リポジトリ以外のサービスによってすでに占有されていないことを確認します。
作成後
git statusブランチが期待されるブランチと一致することを確認します。.worktree-ports.jsonが存在することを確認します。- アプリが割り当てられたアプリポートで起動することを確認します。
- DB およびキャッシュのエンドポイントが分離されたポートをターゲットにしていることを確認します。
削除前
- ブランチにアップストリームがあり、意図したとおりにマージされていることを確認します。
- コミットされていないファイルが残っていないことを確認します。
- 実行中のコンテナ/プロセスがこのワークツリーパスに依存していないことを確認します。
CI およびチーム統合
- タスク I にマッピングされるワークツリーパス命名を使用します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Git Worktree Manager
Tier: POWERFUL
Category: Engineering
Domain: Parallel Development & Branch Isolation
Overview
Use this skill to run parallel feature work safely with Git worktrees. It standardizes branch isolation, port allocation, environment sync, and cleanup so each worktree behaves like an independent local app without stepping on another branch.
This skill is optimized for multi-agent workflows where each agent or terminal session owns one worktree.
Core Capabilities
- Create worktrees from new or existing branches with deterministic naming
- Auto-allocate non-conflicting ports per worktree and persist assignments
- Copy local environment files (
.env*) from main repo to new worktree - Optionally install dependencies based on lockfile detection
- Detect stale worktrees and uncommitted changes before cleanup
- Identify merged branches and safely remove outdated worktrees
When to Use
- You need 2+ concurrent branches open locally
- You want isolated dev servers for feature, hotfix, and PR validation
- You are working with multiple agents that must not share a branch
- Your current branch is blocked but you need to ship a quick fix now
- You want repeatable cleanup instead of ad-hoc
rm -rfoperations
Key Workflows
1. Create a Fully-Prepared Worktree
- Pick a branch name and worktree name.
- Run the manager script (creates branch if missing).
- Review generated port map.
- Start app using allocated ports.
python scripts/worktree_manager.py \
--repo . \
--branch feature/new-auth \
--name wt-auth \
--base-branch main \
--install-deps \
--format text
If you use JSON automation input:
cat config.json | python scripts/worktree_manager.py --format json
# or
python scripts/worktree_manager.py --input config.json --format json
2. Run Parallel Sessions
Recommended convention:
- Main repo: integration branch (
main/develop) on default port - Worktree A: feature branch + offset ports
- Worktree B: hotfix branch + next offset
Each worktree contains .worktree-ports.json with assigned ports.
3. Cleanup with Safety Checks
- Scan all worktrees and stale age.
- Inspect dirty trees and branch merge status.
- Remove only merged + clean worktrees, or force explicitly.
python scripts/worktree_cleanup.py --repo . --stale-days 14 --format text
python scripts/worktree_cleanup.py --repo . --remove-merged --format text
4. Docker Compose Pattern
Use per-worktree override files mapped from allocated ports. The script outputs a deterministic port map; apply it to docker-compose.worktree.yml.
See docker-compose-patterns.md for concrete templates.
5. Port Allocation Strategy
Default strategy is base + (index * stride) with collision checks:
- App:
3000 - Postgres:
5432 - Redis:
6379 - Stride:
10
See port-allocation-strategy.md for the full strategy and edge cases.
Script Interfaces
python scripts/worktree_manager.py --help- Create/list worktrees
- Allocate/persist ports
- Copy
.env*files - Optional dependency installation
python scripts/worktree_cleanup.py --help- Stale detection by age
- Dirty-state detection
- Merged-branch detection
- Optional safe removal
Both tools support stdin JSON and --input file mode for automation pipelines.
Common Pitfalls
- Creating worktrees inside the main repo directory
- Reusing
localhost:3000across all branches - Sharing one database URL across isolated feature branches
- Removing a worktree with uncommitted changes
- Forgetting to prune old metadata after branch deletion
- Assuming merged status without checking against the target branch
Best Practices
- One branch per worktree, one agent per worktree.
- Keep worktrees short-lived; remove after merge.
- Use a deterministic naming pattern (
wt-<topic>). - Persist port mappings in file, not memory or terminal notes.
- Run cleanup scan weekly in active repos.
- Use
--format jsonfor machine flows and--format textfor human review. - Never force-remove dirty worktrees unless changes are intentionally discarded.
Validation Checklist
Before claiming setup complete:
git worktree listshows expected path + branch..worktree-ports.jsonexists and contains unique ports..envfiles copied successfully (if present in source repo).- Dependency install command exits with code
0(if enabled). - Cleanup scan reports no unintended stale dirty trees.
References
- port-allocation-strategy.md
- docker-compose-patterns.md
- README.md for quick start and installation details
Decision Matrix
Use this quick selector before creating a new worktree:
- Need isolated dependencies and server ports -> create a new worktree
- Need only a quick local diff review -> stay on current tree
- Need hotfix while feature branch is dirty -> create dedicated hotfix worktree
- Need ephemeral reproduction branch for bug triage -> create temporary worktree and cleanup same day
Operational Checklist
Before Creation
- Confirm main repo has clean baseline or intentional WIP commits.
- Confirm target branch naming convention.
- Confirm required base branch exists (
main/develop). - Confirm no reserved local ports are already occupied by non-repo services.
After Creation
- Verify
git statusbranch matches expected branch. - Verify
.worktree-ports.jsonexists. - Verify app boots on allocated app port.
- Verify DB and cache endpoints target isolated ports.
Before Removal
- Verify branch has upstream and is merged when intended.
- Verify no uncommitted files remain.
- Verify no running containers/processes depend on this worktree path.
CI and Team Integration
- Use worktree path naming that maps to task ID (
wt-1234-auth). - Include the worktree path in terminal title to avoid wrong-window commits.
- In automated setups, persist creation metadata in CI artifacts/logs.
- Trigger cleanup report in scheduled jobs and post summary to team channel.
Failure Recovery
- If
git worktree addfails due to existing path: inspect path, do not overwrite. - If dependency install fails: keep worktree created, mark status and continue manual recovery.
- If env copy fails: continue with warning and explicit missing file list.
- If port allocation collides with external service: rerun with adjusted base ports.
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (6,681 bytes)
- 📎 README.md (1,291 bytes)
- 📎 references/docker-compose-patterns.md (1,149 bytes)
- 📎 references/port-allocation-strategy.md (1,030 bytes)
- 📎 scripts/worktree_cleanup.py (6,620 bytes)
- 📎 scripts/worktree_manager.py (8,566 bytes)