Turn an issue title or ticket ID into a consistent, git-valid branch name like fix/JIRA-123-login-button-not-working, with explicit type, case and length rules.
---
name: git-branch-name
description: Generates a consistent git branch name such as feature/add-user-authentication-oauth or fix/JIRA-123-login-button-not-working from an issue title, ticket ID or feature description, and checks it with git check-ref-format. Use when asked to name a branch, create a branch for a ticket, or suggest a branch name for a change.
compatibility: Name generation needs nothing; validating or creating the branch needs git.
metadata:
version: "1.0.0"
---
# Git Branch Name Generator
Turns a title like "JIRA-123: Fix login button not working" into `fix/JIRA-123-login-button-not-working`. If the repository already has a naming convention (check `CONTRIBUTING.md` and `git branch -r | head -30`), follow that convention instead of these defaults.
## Format
```
<type>/<ticket-id>-<description> when a ticket ID is present
<type>/<description> otherwise
```
## Rules
1. **Type** - use the type the user gives. Otherwise infer it from the first word of the title: `fix`, `bug`, `bugfix` → `fix`; `hotfix` → `hotfix`; `refactor` → `refactor`; `docs`/`doc` → `docs`; `test`/`tests` → `test`; anything else → `feature`. When the first word set the type, drop it from the description (so "Fix login button" does not become `fix/fix-login-button`). Use `hotfix` only when the user says it is an urgent production fix.
2. **Ticket ID** - a leading key such as `JIRA-123`, `ABC-42` or `#482` (optionally followed by `:` or `-`) is moved to the front of the description. It keeps the tracker's own case (`JIRA-123`) so it matches the ticket exactly; `#` is dropped.
3. **Description** - lowercase ASCII words joined by single hyphens. Accents are transliterated (`café` → `cafe`); other punctuation is removed.
4. **Filler words** removed: a, an, the, with, and, or, of, for, to, in, on, at, by. Meaningful words such as `not` stay.
5. **Length** - the description after the ticket ID is at most 50 characters, cut at a word boundary, never mid-word.
6. **Validity** - the result must pass `git check-ref-format --branch <name>`. The rules above already avoid spaces, `..`, `~`, `^`, `:`, `?`, `*`, `[`, `\`, trailing `.` or `/`, and `@{`.
## Workflow
1. Take the title (and ticket ID, if separate). Ask only if the title is empty or the type is genuinely ambiguous.
2. Apply the rules (the reference implementation below gives the same output).
3. Validate: `git check-ref-format --branch "fix/JIRA-123-login-button-not-working"`.
4. Check for a clash: `git branch --list "<name>"` and `git ls-remote --heads origin "<name>"` (read-only). If taken, append `-2` or ask.
5. Return the name. Create it (`git switch -c <name>`) only if the user asked you to create the branch.
## Reference implementation (Python 3)
```python
import re, sys, unicodedata
TYPE_WORDS = {"fix": "fix", "bug": "fix", "bugfix": "fix", "hotfix": "hotfix",
"refactor": "refactor", "docs": "docs", "doc": "docs", "test": "test", "tests": "test"}
STOP = {"a", "an", "the", "with", "and", "or", "of", "for", "to", "in", "on", "at", "by"}
TICKET = re.compile(r"^\s*([A-Za-z][A-Za-z0-9]+-\d+|#\d+)\s*[:\-]?\s*")
def branch_name(title, kind=None, max_len=50):
ticket = None
m = TICKET.match(title)
if m:
ticket = m.group(1).lstrip("#")
title = title[m.end():]
ascii_title = unicodedata.normalize("NFKD", title).encode("ascii", "ignore").decode()
words = re.findall(r"[a-z0-9]+", ascii_title.lower())
if kind is None:
kind = TYPE_WORDS.get(words[0], "feature") if words else "feature"
if words and words[0] in TYPE_WORDS:
words = words[1:] # the leading word became the type
words = [w for w in words if w not in STOP]
desc = ""
for w in words: # cut at a word boundary
nxt = f"{desc}-{w}" if desc else w
if len(nxt) > max_len:
break
desc = nxt
if not desc:
desc = "change"
slug = f"{ticket}-{desc}" if ticket else desc
return f"{kind}/{slug}"
if __name__ == "__main__":
for t in sys.argv[1:]:
print(branch_name(t))
```
This package ships no script file. To run the reference, save the block above as `branch_name.py` in a scratch directory, then: `python3 branch_name.py "JIRA-123: Fix login button not working"`
## Examples
| Input | Output |
|-------|--------|
| Add user authentication with OAuth | `feature/add-user-authentication-oauth` |
| JIRA-123: Fix login button not working | `fix/JIRA-123-login-button-not-working` |
| Refactor the payment service | `refactor/payment-service` |
| #482 Docs: update README for v2 release | `docs/482-update-readme-v2-release` |
| Add support for exporting very large monthly invoice reports to PDF and CSV formats | `feature/add-support-exporting-very-large-monthly-invoice` |
## Limitations
- Type inference looks only at the first word; pass the type explicitly when the title does not start with it (for example "Login button not working" → ask or pass `fix`).
- Teams that require fully lowercase names should lowercase the ticket ID too; say which rule you applied.
Write a Conventional Commits message from staged git changes, with a read-only helper script that gathers the staged diff and recent commit style.
Draft a PR title and description from the branch's real commits and diff, fill the repo's PR template, and leave unverified checklist items unticked.
Work on multiple branches simultaneously
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A developer picks up a Jira ticket and wants a branch name that follows the team's type/ticket/description pattern without typing it by hand.
Branch name for: JIRA-123: Fix login button not working
fix/JIRA-123-login-button-not-working — type fix inferred from the leading word (which is then dropped), ticket key kept as written, description lowercase and hyphenated, 33 characters after the type prefix, and confirmation that git check-ref-format --branch accepts it. The branch is not created unless asked.
AI Agent Skills are reusable workflow packages that extend your AI coding assistant with multi-step capabilities. Install git-branch-name by following these steps.
SKILL.md inside, in the location documented by your client. Do not assume every AI application reads the same directory.Requires an Agent Skills-compatible client; supported locations and activation vary by version. Read the SKILL.md setup guide. MCP connects tools and data and does not, by itself, install a skill.
Write a Conventional Commits message from staged git changes, with a read-only helper script that gathers the staged diff and recent commit style.
Draft a PR title and description from the branch's real commits and diff, fill the repo's PR template, and leave unverified checklist items unticked.
Work on multiple branches simultaneously