Conventional Commits v1.0.0 分支、工作树命名及提交信息规范,适用于 GitHub 与 GitLab 项目,用于创建分支和命名工作树等场景。
Follow Conventional Commits v1.0.0 for both branch names and commit messages — consistent naming lets tools auto-generate changelogs, enforce SemVer bumps, and filter history by concern.
Format: <type>/[issue-]<description> — lowercase, hyphens only, no special chars except /.
text
feat/user-authentication
feat/42-user-authentication
fix/login-race-condition
fix/87-login-race-condition
docs/api-reference-update
refactor/payment-module
Prefix with the issue number when one exists — GitHub and GitLab auto-link it and it makes git log immediately traceable to the tracker. Keep the description under 50 characters — most git UIs truncate branch names in lists around that length. Match the type to the work you're doing — this is the contract readers use to understand the branch purpose at a glance.
NEVER include worktree in a branch name — git worktrees are a local checkout mechanism, not a branch concept; the name would leak implementation details into the remote and confuse other contributors.
Worktrees are local checkout directories — they never appear in the remote. Place them under .claude/worktrees/ and name them by replacing the branch / separator with -.
text
git worktree add .claude/worktrees/feat-user-authentication feat/user-authentication
git worktree add .claude/worktrees/fix-87-login-race-condition fix/87-login-race-condition
The directory name mirrors the branch name so git worktree list stays readable and each worktree is immediately traceable to its branch without inspecting the checkout. Run git worktree list before creating a new one — reuse an existing worktree if it already covers the same branch.
Keep worktrees scoped to a single branch. Doing unrelated work inside someone else's worktree obscures which changes belong where and makes cleanup error-prone.
Remove the worktree once its branch is merged — either after a local merge or after the pull/merge request is closed on the remote. Stale worktrees accumulate and make git worktree list unreadable.
bash
git worktree remove .claude/worktrees/feat-user-authentication # branch merged locally
git worktree prune # remove refs to already-deleted directories
text
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types:
TypeSemVerWhenfeatMINORNew featurefixPATCHBug fixdocs—Docs onlystyle—Formatting, no logic changerefactor—Restructure, no feature/fixperf—Performance improvementtest—Add/fix testsbuild—Build system, depsci—CI configchore—Anything else (not src/test)revert—Reverts a previous commit
Rules:
! after type/scope, or add BREAKING CHANGE: footer (triggers MAJOR bump) — body-only descriptions are invisible to changelog toolsrevert commits SHOULD include This reverts commit <hash>. in the body — git revert generates this automatically; don't strip itCo-authored-by trailer for Claude or any other AI agent to commitsExamples:
text
feat(auth): add JWT token refresh
text
fix: prevent race condition on concurrent requests
Introduce request ID and reference to latest request.
Dismiss responses from stale requests.
text
refactor!: drop support for Go 1.18
BREAKING CHANGE: Go 1.18 no longer supported; uses stdlib APIs from 1.21+
Both GitHub and GitLab detect keywords in commit messages and automatically close the referenced issue when the commit lands on the default branch. Place the reference in the footer (preferred — keeps the subject line clean).
Keywords: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved — case-insensitive.
GitHub:
text
fix(auth): prevent token expiry race condition
Closes #42
Closes owner/repo#99
main)Closes owner/repo#42Closes #42, closes #43GitLab:
text
feat: add dark mode support
Resolves #101
Closes group/project#42
Closes group/project#42Closes #101, closes #102Tip: Pair with the commit type — fix: closing a bug issue, feat: closing a feature request — keeps the changelog semantically coherent.
MistakeFixfeat: Added login page``feat: add login page — imperative, no capitalfix: fix bug.``fix: fix bug — no trailing periodSubject over 72 charsShorten; move detail to bodyBreaking change only in bodyAdd ! or BREAKING CHANGE: footer — tools won't detect body-onlyfeat(adding-auth): ...``feat(auth): ... — scope is a noun, not a verbCloses #42 in subject lineMove to footer — keeps subject clean and parseable
feat/auth-* branch → feat(auth): commitsfeat(auth): throughout, not feat(user): mid-way