| name | git-worktree |
| description | Git worktreeを使った並列開発を支援する。複数のClaude Codeインスタンスで同時に異なるブランチの作業を行う際に使用する。"worktree"、"並列開発"、"別ブランチで作業"などのキーワードで発動。 |
Git Worktree スキル
概要
git worktreeは、1つのリポジトリで複数の作業ディレクトリを持つ機能。
これにより、複数のClaude Codeインスタンスで異なるブランチを並列開発できる。
ディレクトリ構成
~/workspace/
├── nelchan/ # メインリポジトリ (main)
└── .worktrees/
└── nelchan/ # nelchanのworktree格納場所
├── 001-feature-a/ # 機能Aのworktree
└── 002-feature-b/ # 機能Bのworktree
基本操作
Worktreeの作成
spec-kit連携の場合(推奨):
/speckit.specify <機能の説明>
git worktree add ~/.worktrees/nelchan/<branch-name> <branch-name>
手動でブランチとworktreeを同時に作成:
git worktree add -b <new-branch> ~/.worktrees/nelchan/<new-branch> main
既存ブランチからworktreeを作成:
git worktree add ~/.worktrees/nelchan/<branch-name> <branch-name>
Worktree一覧
git worktree list
Worktreeの削除
git worktree remove ~/.worktrees/nelchan/<branch-name>
git worktree remove ~/.worktrees/nelchan/<branch-name>
git branch -d <branch-name>
強制削除(未コミットの変更がある場合)
git worktree remove --force ~/.worktrees/nelchan/<branch-name>
spec-kit + git-worktree ワークフロー
Phase 1: 仕様策定(mainリポジトリ)
/speckit.specify ユーザー認証機能を追加
/speckit.plan
/speckit.tasks
Phase 2: 並列開発環境の準備
git worktree add ~/.worktrees/nelchan/001-user-auth 001-user-auth
Phase 3: 実装(Worktreeで)
claude --cwd ~/.worktrees/nelchan/001-user-auth
/speckit.implement
Phase 4: PR作成
git push -u origin 001-user-auth
gh pr create --title "feat: ユーザー認証機能を追加" --body "..."
Phase 5: クリーンアップ
git worktree remove ~/.worktrees/nelchan/001-user-auth
git branch -d 001-user-auth
並列開発のパターン
複数機能を同時開発
Terminal 1 (main):
└── 仕様策定・レビュー作業
Terminal 2 (001-feature-a worktree):
└── 機能A実装
Terminal 3 (002-feature-b worktree):
└── 機能B実装
注意点
-
specsディレクトリはmainで管理
- 仕様書はmainブランチで作成・管理
- worktreeでは実装のみ行う
-
コミットはworktreeごとに独立
- 各worktreeで独立してコミット可能
- pushはworktreeから直接実行
-
ロックされたブランチ
- あるworktreeでチェックアウト中のブランチは他でチェックアウト不可
git worktree listで確認
トラブルシューティング
Worktreeが残っている場合
git worktree prune
ブランチがロックされている場合
git worktree list
git worktree remove <path>