1
---
2
name: conventional-branch
3
description: 'Create Git branches following the Conventional Branch specification (feature/, bugfix/, hotfix/, release/, chore/, plus AI agent prefixes ai/, copilot/, cursor/, claude/, codex/). Use when creating a new branch, naming a branch, or checking whether a branch name complies with the spec.'
4
---
5
6
# Conventional Branch
7
8
Create Git branches that follow the [Conventional Branch](https://conventionalbranch.org) specification — a simple, consistent convention for naming Git branches.
9
10
## Branch Name Format
11
12
```
13
<type>/<description>
14
```
15
16
### Branch Types
17
18
**Purpose prefixes** — describe the intent of the work:
19
20
| Type | Alias | Purpose |
21
|------|-------|---------|
22
| `feature/` | `feat/` | New features or enhancements |
23
| `bugfix/` | `fix/` | Bug fixes |
24
| `hotfix/` | — | Urgent production fixes |
25
| `release/` | — | Release preparation (dots allowed in version: `release/v1.2.0`) |
26
| `chore/` | — | Non-code tasks (deps, docs, config) |
27
28
**AI agent source prefixes** — identify branches generated by AI coding agents:
29
30
| Type | Alias | Purpose |
31
|------|-------|---------|
32
| `ai/` | — | Generic prefix for any AI coding agent |
33
| `copilot/` | — | GitHub Copilot |
34
| `cursor/` | — | Cursor |
35
| `claude/` | — | Claude Code by Anthropic |
36
| `codex/` | — | OpenAI Codex |
37
38
Use a vendor-specific prefix when you know which agent is producing the branch; use `ai/` as a vendor-neutral fallback.
39
40
### Trunk Branches
41
42
`main`, `master`, and `develop` are trunk branches — they do not use a prefix. Never create new branches with the same names as trunk branches; branch off them instead.
43
44
## Naming Rules
45
46
- **Lowercase only** — no uppercase letters anywhere
47
- **Alphanumerics, hyphens, and dots** — `a-z`, `0-9`, `-`, `.`
48
- **Dots** are allowed in any description, typically for version numbers (e.g., `release/v1.2.0`, `chore/upgrade-node-v20.11`)
49
- **No underscores, spaces, or special characters**
50
- **No consecutive hyphens** (`--`), **dots** (`..`), or **hyphen-dot adjacency** (`-.` or `.-`)
51
- **No leading or trailing hyphens or dots** in the description
52
53
## Valid Examples
54
55
```
56
main
57
master
58
develop
59
feature/add-login-page
60
feat/add-login-page
61
bugfix/fix-header-bug
62
fix/header-bug
63
hotfix/security-patch
64
release/v1.2.0
65
chore/update-dependencies
66
feature/issue-123-new-login
67
ai/refactor-auth-flow
68
copilot/add-login-page
69
cursor/fix-header-bug
70
claude/security-patch
71
codex/optimize-query
72
```
73
74
## Invalid Examples
75
76
| Branch | Problem |
77
|--------|---------|
78
| `Feature/Add-Login` | Uppercase letters |
79
| `feature/new--login` | Consecutive hyphens |
80
| `feature/-new-login` | Leading hyphen |
81
| `feature/new-login-` | Trailing hyphen |
82
| `release/v1.-2.0` | Hyphen adjacent to dot |
83
| `fix/header bug` | Space |
84
| `fix/header_bug` | Underscore |
85
| `unknown/some-task` | Unknown prefix type |
86
87
## Description Guidelines
88
89
- Use **kebab-case** with 2-5 words
90
- Be descriptive but concise (~50 chars total)
91
- Good: `add-oauth-login`, `fix-header-overflow`, `update-ci-config`
92
- Bad: `fix-bug`, `new-feature`
93
94
## Workflow
95
96
**Follow these steps:**
97
98
**Step 1 — Determine Branch Type**
99
100
Ask the user (if not already clear):
101
102
- **Branch type** — default to `feature` when uncertain
103
- **Brief description** — what the branch is for
104
105
If the user mentions a ticket or issue number, include it in the description (e.g., `feature/issue-123-add-oauth`).
106
107
**Step 2 — Validate the Name**
108
109
Check the assembled name against the **Naming Rules** above. If any rule fails, fix it:
110
111
- Lowercase everything
112
- Replace underscores and spaces with hyphens
113
- Collapse consecutive hyphens
114
- Strip leading/trailing hyphens
115
116
**Step 3 — Detect the Base Branch**
117
118
Different repos use different trunk branches. Detect which one this repo uses:
119
120
```bash
121
# Prefer the remote's default branch
122
git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|^origin/||'
123
```
124
125
If that returns nothing, check which trunk branch exists locally (priority order: `develop`, `main`, `master`):
126
127
```bash
128
for b in develop main master; do
129
git show-ref --verify --quiet "refs/heads/$b" && echo "$b" && break
130
done
131
```
132
133
**Step 4 — Create and Checkout**
134
135
```bash
136
git checkout <base>
137
git pull origin <base>
138
git checkout -b <type>/<description>
139
```
140
141
**Step 5 — Confirm**
142
143
Tell the user:
144
- The branch name that was created
145
- That they are now on the new branch
146
- Remind them: `git push -u origin <branch-name>` when ready
147
148
## Validation
149
150
[commit-check](https://github.com/commit-check/commit-check) validates branch names against the specification. Run `commit-check --branch`, use its `check-branch` pre-commit hook, or [commit-check-action](https://github.com/commit-check/commit-check-action) in GitHub Actions. Configuration for GitHub rulesets, GitLab, Bitbucket and Git hooks is at https://conventionalbranch.org/enforce/.
151
152
## Relationship with Conventional Commits
153
154
Conventional Branch complements [Conventional Commits](https://www.conventionalcommits.org):
155
156
| Conventional Branch | Typical Conventional Commit |
157
|---------------------|----------------------------|
158
| `feature/add-login` | `feat: add login page` |
159
| `bugfix/fix-header` | `fix: header overflow on mobile` |
160
| `chore/update-deps` | `chore: bump lodash to 5.0` |
161
| `release/v1.2.0` | `chore: release v1.2.0` |
162
163
Align the branch type with commit types where possible (e.g., `feature/*` branches with `feat:` commits).
164