creating-git-branch

p-chan's avatarfrom p-chan

Git リポジトリの慣習に則って新しいブランチを作成します。ユーザーがブランチの作成を求めたときや、エージェントがブランチを作成するときに必ず使用してください。

⭐8stars🔀0forks📁View on GitHub🕐Updated Jan 4, 2026

When & Why to Use This Skill

This Claude skill automates the creation of Git branches by intelligently adhering to repository-specific conventions. It analyzes existing branch patterns and project documentation to generate consistent, professional branch names, streamlining the development workflow and reducing manual naming errors for both human developers and AI agents.

Use Cases

  • Automated Feature Branching: Quickly create new branches for features (e.g., 'feature/user-auth-logic') that perfectly match the project's established naming style.
  • Consistent Bug Fix Naming: Ensure bug fix branches follow the correct prefix and format (e.g., 'fix/header-alignment') by analyzing the repository's history.
  • AI-Driven Development: Enable AI agents to autonomously initialize their work environment with correctly formatted branches before starting code modifications.
  • Convention Enforcement: Maintain repository cleanliness by automatically detecting and applying naming rules found in README.md or configuration files.
namecreating-git-branch
descriptionGit リポジトリの慣習に則って新しいブランチを作成します。ユーザーがブランチの作成を求めたときや、エージェントがブランチを作成するときに必ず使用してください。
allowed-toolsBash(git branch:*), Bash(grep:*), Bash(head:*), Bash(sed:*), Bash(cut:*), Bash(sort:*), Bash(xargs:*)

Git ブランチ作成

前提

README.md やメモリファイル(AGENTS.md や CLAUDE.md など)にブランチ名の規約がある場合、それに従う。

以下のワークフローは、明確な規約がない場合に実行します。

ワークフロー

1. 情報収集

既存のブランチ名を取得:

git branch --sort=-committerdate | grep -v -E '^\*?\s*(main|master)\s*$' | head -10

2. 判定

スタイル判定

既存ブランチから以下を判定します。

  • シンプル形式: add-feature、fix-bug などスラッシュなし
  • プレフィックス付き: feature/xxx、fix/xxx などスラッシュを含む
例外
  • 複数スタイルが混在する場合、最も使用頻度の高いスタイルを採用
  • 既存ブランチがない場合は、どのスタイルを使用するかユーザーに確認

プレフィックス判定

プレフィックス付きスタイルの場合、以下のコマンドでプレフィックス一覧を取得します:

git branch --all | head -100 | grep -v -E 'HEAD|main\s*$|master\s*$' | sed -E 's/^\*?\s*//; s|remotes/origin/||' | grep '/' | cut -d'/' -f1 | sort -u | xargs | sed 's/ /, /g'

3. ブランチ名生成

判定したスタイルに基づき、2〜5 単語程度のブランチ名を生成します。

  • 動詞始まり(add、update、fix、remove など)
  • ハイフン区切り
  • 変更内容を簡潔に表現

4. ブランチ作成

生成されたブランチ名を表示し、ブランチを作成します。

git switch -c <branch-name>