Git Branch Creation
Enhance branch creation with automatic detection of naming conventions and intelligent base branch selection.
Quick Reference
Workflow:
- •✓ Check for uncommitted changes (warn if present)
- •✓ Confirm base branch (mainline by default)
- •✓ Detect naming convention (conventional commits)
- •✓ Generate branch name (type/description)
- •✓ Create and verify branch
Branch naming:
- •With conventional commits:
type/description(feat/, fix/, docs/, etc.) - •Without:
description(kebab-case) - •Always lowercase with hyphens
Branch types: feat, fix, docs, refactor, test, chore, build, ci
Sections: Current Git State • Core Workflow • Branch Naming • Examples
Current Git State
- •Current branch: !
git rev-parse --abbrev-ref HEAD - •Mainline branch: !
${CLAUDE_PLUGIN_ROOT}/skills/branch/scripts/detect-mainline.sh - •Has uncommitted changes: !
git diff-index --quiet HEAD -- 2>/dev/null && echo "no" || echo "yes"
Core Workflow
Follow these steps when the user requests branch creation:
1. Check for Uncommitted Changes
Use git state from dynamic context above to check for uncommitted changes.
If uncommitted changes exist:
Warn user: "You have uncommitted changes. They will come with you to the new branch. Consider committing or stashing them first."
This is informational only - uncommitted changes don't prevent branch creation, but the user should be aware.
2. Confirm Base Branch
Default base branch:
- •Use mainline branch from dynamic context (typically
mainormaster)
Alternative base branches:
- •If user is on a feature branch and wants to branch from it, use current branch
- •For release workflows, may branch from
developor specific release branch
Ask for confirmation if uncertain:
Use AskUserQuestion if the base branch is ambiguous:
"Create branch from '{base_branch}'?"
Options: Yes / Use current branch / Specify different branch
3. Detect Naming Convention
Invoke the detect-conventions skill to determine branch naming style.
4. Generate Branch Name
Use results from the detect-conventions skill to generate appropriate branch name.
Conventional Commits Branch Naming
If conventional commits are used:
| Type | Branch Prefix | Use For |
|---|---|---|
| feat | feat/ | New features |
| fix | fix/ | Bug fixes |
| docs | docs/ | Documentation |
| refactor | refactor/ | Code refactoring |
| test | test/ | Test additions |
| chore | chore/ | Maintenance tasks |
| build | build/ | Build system changes |
| ci | ci/ | CI/CD changes |
If conventional commits NOT used:
Use simple descriptive names:
- •
feature-description - •
bugfix-description - •
update-description
Naming rules:
- •Use kebab-case (lowercase with hyphens)
- •Be descriptive but concise (3-5 words max)
- •No special characters except hyphens and slashes
- •Start with letter or type prefix
Example transformations:
- •User intent: "add OAuth login" →
feat/oauth-login(with CC) oradd-oauth-login(without CC) - •User intent: "fix memory leak" →
fix/memory-leak(with CC) orfix-memory-leak(without CC)
5. Create Branch
Execute branch creation using the confirmed base branch:
git checkout -b {branch_name} {base_branch}
Or for newer git:
git switch -c {branch_name} {base_branch}
6. Verify and Report
After creation:
- •Verify branch was created:
git branch --list {branch_name} - •Confirm current branch:
git rev-parse --abbrev-ref HEAD - •Report success to user with branch name
Examples
Example 1: Feature Branch with Conventional Commits
User request: "Create a branch for adding user authentication"
Steps:
- •Check uncommitted changes: None ✓
- •Confirm base branch:
main(mainline) ✓ - •Detect conventional commits: Found
commitlint.config.js→ Yes - •Generate name:
feat/user-authentication - •Execute:
git checkout -b feat/user-authentication main - •Report: "Created branch
feat/user-authenticationfrommain"
Example 2: Bug Fix without Conventional Commits
User request: "Make a branch to fix the login bug"
Steps:
- •Check uncommitted changes: None ✓
- •Confirm base branch:
main✓ - •Detect conventional commits: No config, commit history doesn't match → No
- •Generate name:
fix-login-bug - •Execute:
git checkout -b fix-login-bug main - •Report: "Created branch
fix-login-bugfrommain"
Example 3: Branch from Current Feature
User request: "Create a sub-branch for the API refactor"
Steps:
- •Check uncommitted changes: None ✓
- •Confirm base branch: Ask user → User confirms
feat/api-redesigninstead ofmain - •Detect conventional commits: Yes
- •Generate name:
refactor/api-cleanup - •Execute:
git checkout -b refactor/api-cleanup feat/api-redesign - •Report: "Created branch
refactor/api-cleanupfromfeat/api-redesign"
Error Handling
Branch already exists:
if git branch --list {branch_name} | grep -q .; then
# Suggest alternative name or ask to switch to existing
fi
Not in a git repository:
if ! git rev-parse --git-dir > /dev/null 2>&1; then # Report error, suggest git init fi
Task Coordination
At workflow start:
- •Create coordination task with TaskCreate:
- •subject: "Create git branch"
- •activeForm: "Creating git branch"
- •metadata:
{ workflow: "branch", base: "<base-branch>", startedAt: "<timestamp>" }
During workflow:
- •Update task metadata as conventions are detected (from detect-conventions skill)
At workflow end:
- •Update task status to completed
- •Add result metadata:
{ result: { branchName: "<name>" } }
Integration with Other Skills
This skill may be invoked by:
- •
/git:commit- When user tries to commit on mainline branch - •
/git:pr- When preparing to create a PR and no feature branch exists