A

Advanced Branch Name Enforcer Enforcer

Boost productivity with intelligent enforce branch naming conventions. Built for Claude Code with best practices and real-world patterns.

HookCommunitygit workflowv1.0.0MIT
0 views0 copies

Advanced Branch Name Enforcer Enforcer

Validates git branch names against configurable naming conventions, blocking branch creation or pushes that do not conform to the team's branching strategy.

When to Use This Hook

Attach this hook when you need to:

  • Enforce a consistent branch naming convention like type/TICKET-123-description
  • Prevent ad-hoc branch names that make git history and CI pipelines harder to navigate
  • Integrate branch names with issue trackers by requiring ticket IDs in branch names

Consider alternatives when:

  • Your team uses trunk-based development with minimal branching
  • Branch naming is already enforced by your Git hosting platform's branch policies

Quick Start

Configuration

name: advanced-branch-name-enforcer-enforcer type: hook trigger: PreToolUse category: git-workflow

Example Trigger

# Hook triggers before a branch creation or checkout command git checkout -b feat/PROJ-456-add-dark-mode # Enforcer validates the branch name against rules

Example Output

Branch Name Enforcer
  Branch: feat/PROJ-456-add-dark-mode
  Pattern: {type}/{ticket}-{description}
  Type: feat ...................... VALID (in: feat, fix, chore, docs, refactor)
  Ticket: PROJ-456 ............... VALID (matches [A-Z]+-\d+)
  Description: add-dark-mode ..... VALID (lowercase kebab-case)
  Length: 28 chars (max: 63) ..... PASS
Branch name approved.

Core Concepts

Naming Convention Overview

AspectDetails
Type Prefixfeat/, fix/, chore/, docs/, refactor/, hotfix/
Ticket IDJira/Linear-style ticket reference (e.g., PROJ-123)
DescriptionLowercase kebab-case summary of the work
SeparatorForward slash between type and rest, hyphens within
Max Length63 characters (git branch name limit for most tools)

Enforcement Workflow

Branch Command Detected
        |
   Extract Branch Name
        |
   Parse Components
        |
   ā”Œā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”
   |    |    |    |
 Type Ticket Desc Length
   |    |    |    |
   ā””ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”˜
        |
   All Valid?
    /       \
  Yes        No
   |          |
 ALLOW     BLOCK +
           Show Pattern
           + Example

Configuration

ParameterTypeDefaultDescription
patternstring"^(feat|fix|chore|docs|refactor)/[A-Z]+-\\d+-[a-z0-9-]+$"Regex pattern for valid branch names
allowed_typesstring[]["feat","fix","chore","docs","refactor","hotfix"]Valid branch type prefixes
require_ticketbooleantrueRequire a ticket ID in the branch name
max_lengthnumber63Maximum branch name length
exempt_branchesstring[]["main","master","develop","staging"]Branches exempt from naming rules

Best Practices

  1. Exempt Long-Lived Branches - Always exempt main, master, develop, and staging from naming rules. These branches exist outside the feature branching convention.

  2. Keep Descriptions Short but Meaningful - Enforce a maximum description length of 3-5 words in kebab-case. Long branch names are hard to type and display poorly in most git tools.

  3. Match Your Issue Tracker - Configure the ticket pattern to match your issue tracker's format. Jira uses PROJ-123, Linear uses TEAM-123, GitHub uses #123. Align the enforcer accordingly.

  4. Provide a Branch Name Generator - When the enforcer rejects a name, suggest a corrected version. Transforming "my new feature" into "feat/PROJ-0-my-new-feature" reduces friction.

  5. Allow Hotfix Exceptions - Hotfix branches may need expedited creation without a ticket. Allow hotfix/description without requiring a ticket ID for emergency situations.

Common Issues

  1. Case Sensitivity on macOS - macOS file systems are case-insensitive, so feat/Add-Feature and feat/add-feature conflict. Enforce lowercase to prevent this issue.

  2. Slash Depth Limitations - Some git tools handle nested slashes (feat/auth/login) differently. Limit to a single slash separator unless your tooling supports deeper nesting.

  3. Renaming Existing Branches - The enforcer validates at creation time but cannot retroactively fix existing non-conforming branches. Run a one-time audit with git branch -m to rename legacy branches.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates