git-workspace-init
Initialize a new git worktree and branch for feature development or bug fixes. Use when: (1) Starting work on a new feature, (2) Beginning a bug fix, (3) Creating an isolated workspace for any task, (4) You want to work in parallel on multiple branches. This skill handles branch naming with conventional branch conventions, worktree creation, and remote push setup.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o git-workspace-init.zip https://jpskill.com/download/17527.zip && unzip -o git-workspace-init.zip && rm git-workspace-init.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17527.zip -OutFile "$d\git-workspace-init.zip"; Expand-Archive "$d\git-workspace-init.zip" -DestinationPath $d -Force; ri "$d\git-workspace-init.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
git-workspace-init.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
git-workspace-initフォルダができる - 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-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Git Workspace Init
conventional branch naming の規則に従って、適切に命名されたブランチを持つ、分離された git worktree を初期化します。
使用場面
- 新しいフィーチャーの開発開始時
- バグ修正の開始時
- ホットフィックスの作成時
- ドキュメントの更新時
- リファクタリング作業時
- 分離されたワークスペースが必要なあらゆるタスク
前提条件
- リモートが設定された Git リポジトリ
- ブランチをプッシュする書き込み権限
ワークフローの概要
- タスクの詳細を取得 → タイプと説明を尋ねる (またはコマンドから受け入れる)
- ブランチ名を生成 → conventional branch naming を適用
- worktree を作成 → 分離されたワークスペースをセットアップ
- リモートにプッシュ → origin 上のブランチを追跡
- 移動 → 新しいワークスペースに切り替え
ステップ 1: タスク情報の収集
ユーザーに尋ねるか、コマンド引数から受け入れます。
タスクタイプ
| Type | Use Case | Example |
|---|---|---|
feat |
新機能 | feat/user-authentication |
fix |
バグ修正 | fix/login-validation-error |
hotfix |
緊急のプロダクション修正 | hotfix/security-patch |
docs |
ドキュメント | docs/api-reference |
refactor |
コードの再構築 | refactor/extract-service |
test |
テストの追加 | test/auth-integration |
chore |
メンテナンス | chore/upgrade-dependencies |
perf |
パフォーマンスの改善 | perf/optimize-queries |
ci |
CI/CD の変更 | ci/add-deploy-workflow |
style |
コードスタイル/フォーマット | style/apply-prettier |
タスクの説明
ブランチ名のサフィックスとなる簡単な説明:
- 小文字を使用
- スペースにはハイフンを使用
- 簡潔かつ記述的に
例:
- "user authentication" →
user-authentication - "fix validation error" →
validation-error - "add dark mode" →
dark-mode
ステップ 2: ブランチ名の生成
形式: <type>/<description>
# Examples
feat/user-authentication
fix/null-pointer-exception
hotfix/xss-vulnerability
docs/installation-guide
refactor/extract-user-service
命名規則
- 小文字のみ -
feat/Add-User→feat/add-user - スペースにはハイフン -
fix/login error→fix/login-error - 特殊文字は使用しない -
a-z,0-9,-,/のみ - 簡潔に - 全体で 50 文字未満に
- 記述的に - 実行される作業を示すように
ヘルパー関数
import re
def generate_branch_name(task_type: str, description: str) -> str:
"""Generate conventional branch name from type and description."""
valid_types = ["feat", "fix", "hotfix", "docs", "refactor", "test", "chore", "perf", "ci", "style"]
if task_type not in valid_types:
raise ValueError(f"Invalid type '{task_type}'. Must be one of: {', '.join(valid_types)}")
# Normalize description
normalized = description.lower().strip()
# Replace spaces and underscores with hyphens
normalized = re.sub(r'[\s_]+', '-', normalized)
# Remove invalid characters
normalized = re.sub(r'[^a-z0-9-]', '', normalized)
# Remove consecutive hyphens
normalized = re.sub(r'-+', '-', normalized)
# Trim hyphens from ends
normalized = normalized.strip('-')
return f"{task_type}/{normalized}"
ステップ 3: Git Worktree の作成
Worktree を使用すると、スタッシュや切り替えを行わずに、複数のブランチで同時に作業できます。
デフォルトの Worktree の場所
Worktree は、リポジトリのルートにある .worktrees ディレクトリに作成されます。
my-project/
├── .worktrees/
│ ├── feat-user-auth/ # Worktree for feat/user-auth
│ └── fix-login-error/ # Worktree for fix/login-error
├── src/
└── ...
Worktree 作成コマンド
# Get repository root
REPO_ROOT=$(git rev-parse --show-toplevel)
# Define worktree directory (replace / with - for directory name)
BRANCH_NAME="feat/user-authentication"
WORKTREE_DIR="$REPO_ROOT/.worktrees/${BRANCH_NAME//\//-}"
# Ensure .worktrees directory exists
mkdir -p "$REPO_ROOT/.worktrees"
# Create worktree with new branch from main/master
git worktree add -b "$BRANCH_NAME" "$WORKTREE_DIR" origin/main
ワークフロー
import subprocess
import os
def create_worktree(branch_name: str, base_branch: str = "main") -> str:
"""Create a new worktree for the given branch."""
# Get repo root
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True, check=True
)
repo_root = result.stdout.strip()
# Create worktree directory name (replace / with -)
worktree_dir_name = branch_name.replace("/", "-")
worktree_path = os.path.join(repo_root, ".worktrees", worktree_dir_name)
# Ensure .worktrees directory exists
os.makedirs(os.path.join(repo_root, ".worktrees"), exist_ok=True)
# Fetch latest from remote
subprocess.run(["git", "fetch", "origin"], check=True)
# Create worktree with new branch
subprocess.run(
["git", "worktree", "add", "-b", branch_name, worktree_path, f"origin/{base_branch}"],
check=True
)
return worktree_path
ステップ 4: リモートへのブランチのプッシュ
リモートリポジトリとの追跡を設定します。
# From within the new worktree
cd "$WORKTREE_DIR"
# Push and set upstream
git push -u origin "$BRANCH_NAME"
ワークフロー
def push_branch(worktree_path: str, branch_name: str):
"""Push the new branch to remote with tracking."""
subprocess.run(
["git", "-C", worktree_path, "push", "-u", "origin", branch_name],
check=True
)
ステップ 5: ワークスペースへの移動
作成後、新しい worktree に移動します。
cd "$WORKTREE_DIR"
pwd
git status
重要: ユーザーに新しいワークスペースのパスを通知して、ターミナルでそこに移動できるようにします。
完全な例
import subprocess
import os
import re
def generate_branch_name(task_type: str, description: str) -> str:
"""Generate conventional branch name."""
valid_types = ["feat", "fix", "hotfix", "docs", "refactor", "test", "chore", "perf", "ci", "style"]
(原文がここで切り詰められています) 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Git Workspace Init
Initialize an isolated git worktree with a properly named branch following conventional branch naming conventions.
When to Use
- Starting a new feature
- Beginning a bug fix
- Creating a hotfix
- Documentation updates
- Refactoring work
- Any task needing an isolated workspace
Prerequisites
- Git repository with a remote configured
- Write access to push branches
Workflow Overview
- Get task details → Ask for type and description (or accept from command)
- Generate branch name → Apply conventional branch naming
- Create worktree → Set up isolated workspace
- Push to remote → Track branch on origin
- Navigate → Switch to new workspace
Step 1: Gather Task Information
Ask the user for or accept from command arguments:
Task Type
| Type | Use Case | Example |
|---|---|---|
feat |
New feature | feat/user-authentication |
fix |
Bug fix | fix/login-validation-error |
hotfix |
Urgent production fix | hotfix/security-patch |
docs |
Documentation | docs/api-reference |
refactor |
Code restructuring | refactor/extract-service |
test |
Test additions | test/auth-integration |
chore |
Maintenance | chore/upgrade-dependencies |
perf |
Performance improvement | perf/optimize-queries |
ci |
CI/CD changes | ci/add-deploy-workflow |
style |
Code style/formatting | style/apply-prettier |
Task Description
A brief description that will become the branch name suffix:
- Use lowercase
- Use hyphens for spaces
- Keep it concise but descriptive
Examples:
- "user authentication" →
user-authentication - "fix validation error" →
validation-error - "add dark mode" →
dark-mode
Step 2: Generate Branch Name
Format: <type>/<description>
# Examples
feat/user-authentication
fix/null-pointer-exception
hotfix/xss-vulnerability
docs/installation-guide
refactor/extract-user-service
Naming Rules
- Lowercase only -
feat/Add-User→feat/add-user - Hyphens for spaces -
fix/login error→fix/login-error - No special characters - Only
a-z,0-9,-,/ - Concise - Keep under 50 characters total
- Descriptive - Should indicate the work being done
Helper Function
import re
def generate_branch_name(task_type: str, description: str) -> str:
"""Generate conventional branch name from type and description."""
valid_types = ["feat", "fix", "hotfix", "docs", "refactor", "test", "chore", "perf", "ci", "style"]
if task_type not in valid_types:
raise ValueError(f"Invalid type '{task_type}'. Must be one of: {', '.join(valid_types)}")
# Normalize description
normalized = description.lower().strip()
# Replace spaces and underscores with hyphens
normalized = re.sub(r'[\s_]+', '-', normalized)
# Remove invalid characters
normalized = re.sub(r'[^a-z0-9-]', '', normalized)
# Remove consecutive hyphens
normalized = re.sub(r'-+', '-', normalized)
# Trim hyphens from ends
normalized = normalized.strip('-')
return f"{task_type}/{normalized}"
Step 3: Create Git Worktree
Worktrees allow working on multiple branches simultaneously without stashing or switching.
Default Worktree Location
Worktrees are created in a .worktrees directory at the repository root:
my-project/
├── .worktrees/
│ ├── feat-user-auth/ # Worktree for feat/user-auth
│ └── fix-login-error/ # Worktree for fix/login-error
├── src/
└── ...
Create Worktree Commands
# Get repository root
REPO_ROOT=$(git rev-parse --show-toplevel)
# Define worktree directory (replace / with - for directory name)
BRANCH_NAME="feat/user-authentication"
WORKTREE_DIR="$REPO_ROOT/.worktrees/${BRANCH_NAME//\//-}"
# Ensure .worktrees directory exists
mkdir -p "$REPO_ROOT/.worktrees"
# Create worktree with new branch from main/master
git worktree add -b "$BRANCH_NAME" "$WORKTREE_DIR" origin/main
Workflow
import subprocess
import os
def create_worktree(branch_name: str, base_branch: str = "main") -> str:
"""Create a new worktree for the given branch."""
# Get repo root
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True, check=True
)
repo_root = result.stdout.strip()
# Create worktree directory name (replace / with -)
worktree_dir_name = branch_name.replace("/", "-")
worktree_path = os.path.join(repo_root, ".worktrees", worktree_dir_name)
# Ensure .worktrees directory exists
os.makedirs(os.path.join(repo_root, ".worktrees"), exist_ok=True)
# Fetch latest from remote
subprocess.run(["git", "fetch", "origin"], check=True)
# Create worktree with new branch
subprocess.run(
["git", "worktree", "add", "-b", branch_name, worktree_path, f"origin/{base_branch}"],
check=True
)
return worktree_path
Step 4: Push Branch to Remote
Set up tracking with the remote repository:
# From within the new worktree
cd "$WORKTREE_DIR"
# Push and set upstream
git push -u origin "$BRANCH_NAME"
Workflow
def push_branch(worktree_path: str, branch_name: str):
"""Push the new branch to remote with tracking."""
subprocess.run(
["git", "-C", worktree_path, "push", "-u", "origin", branch_name],
check=True
)
Step 5: Navigate to Workspace
After creation, navigate to the new worktree:
cd "$WORKTREE_DIR"
pwd
git status
Important: Inform the user of the new workspace path so they can navigate there in their terminal.
Complete Example
import subprocess
import os
import re
def generate_branch_name(task_type: str, description: str) -> str:
"""Generate conventional branch name."""
valid_types = ["feat", "fix", "hotfix", "docs", "refactor", "test", "chore", "perf", "ci", "style"]
if task_type not in valid_types:
raise ValueError(f"Invalid type. Must be one of: {', '.join(valid_types)}")
normalized = description.lower().strip()
normalized = re.sub(r'[\s_]+', '-', normalized)
normalized = re.sub(r'[^a-z0-9-]', '', normalized)
normalized = re.sub(r'-+', '-', normalized)
normalized = normalized.strip('-')
return f"{task_type}/{normalized}"
def init_workspace(task_type: str, description: str, base_branch: str = "main") -> dict:
"""
Initialize a new git worktree with conventional branch naming.
Args:
task_type: Type of work (feat, fix, hotfix, docs, refactor, test, chore, perf, ci, style)
description: Brief description of the task
base_branch: Branch to base the new branch on (default: main)
Returns:
dict with branch_name, worktree_path, and success status
"""
# Generate branch name
branch_name = generate_branch_name(task_type, description)
print(f"Branch name: {branch_name}")
# Get repo root
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True, check=True
)
repo_root = result.stdout.strip()
# Create worktree path
worktree_dir_name = branch_name.replace("/", "-")
worktree_path = os.path.join(repo_root, ".worktrees", worktree_dir_name)
# Ensure .worktrees exists
os.makedirs(os.path.join(repo_root, ".worktrees"), exist_ok=True)
# Fetch latest
print("Fetching latest from origin...")
subprocess.run(["git", "fetch", "origin"], check=True)
# Create worktree with new branch
print(f"Creating worktree at: {worktree_path}")
subprocess.run(
["git", "worktree", "add", "-b", branch_name, worktree_path, f"origin/{base_branch}"],
check=True
)
# Push branch to remote
print(f"Pushing {branch_name} to origin...")
subprocess.run(
["git", "-C", worktree_path, "push", "-u", "origin", branch_name],
check=True
)
# Verify
print(f"\nWorkspace initialized!")
print(f" Branch: {branch_name}")
print(f" Path: {worktree_path}")
print(f"\nTo start working:")
print(f" cd {worktree_path}")
return {
"branch_name": branch_name,
"worktree_path": worktree_path,
"success": True
}
# Example usage:
# init_workspace("feat", "user authentication")
# init_workspace("fix", "login validation error")
# init_workspace("docs", "API reference update")
Quick Reference
Branch Type Cheat Sheet
| Type | When to Use |
|---|---|
feat |
Adding new functionality |
fix |
Fixing a bug |
hotfix |
Urgent production fix |
docs |
Documentation only |
refactor |
Restructuring without behavior change |
test |
Adding or fixing tests |
chore |
Build, deps, tooling |
perf |
Performance improvements |
ci |
CI/CD pipeline changes |
style |
Formatting, whitespace |
Worktree Commands
# List all worktrees
git worktree list
# Remove a worktree (when done)
git worktree remove <path>
# Prune stale worktrees
git worktree prune
Cleanup After Merge
After your PR is merged:
# Remove the worktree
git worktree remove .worktrees/feat-user-authentication
# Delete the local branch (if not auto-deleted)
git branch -d feat/user-authentication
# Prune remote tracking branches
git fetch --prune
Error Handling
Branch Already Exists
fatal: A branch named 'feat/user-auth' already exists.
Solution: Choose a more specific name or check if work is already in progress.
Worktree Path Already Exists
fatal: '<path>' already exists
Solution: The worktree already exists. Use git worktree list to find it.
No Remote Configured
fatal: No configured push destination.
Solution: Add a remote first: git remote add origin <url>