conventional-git

作者: samber

Conventional Commits v1.0.0 分支命名、工作樹命名及提交訊息標準,適用於 GitHub 與 GitLab 專案。用於建立分支、命名工作樹、撰寫提交、生成提交訊息、審查分支慣例或設定變更日誌自動化。當專案需要一致的 Git 歷史、語意化版本驅動的發佈、可解析的變更日誌生成或自動關閉議題時適用。在使用者詢問如何命名工作樹、建立 Git 工作樹或...時觸發。

npx skills add https://github.com/samber/cc-skills --skill conventional-git

Conventional Commits & Branch Naming

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.

Branch Naming

Format: <type>/[issue-]<description> — lowercase, hyphens only, no special chars except /.

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.

Worktree Naming

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 -.

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.

git worktree remove .claude/worktrees/feat-user-authentication   # branch merged locally
git worktree prune                                                # remove refs to already-deleted directories

Commit Message Format

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

Types:

TypeSemVerWhen
featMINORNew feature
fixPATCHBug fix
docsDocs only
styleFormatting, no logic change
refactorRestructure, no feature/fix
perfPerformance improvement
testAdd/fix tests
buildBuild system, deps
ciCI config
choreAnything else (not src/test)
revertReverts a previous commit

Rules:

  • Subject line ≤ 72 characters — git log and GitHub/GitLab UIs silently truncate longer subjects
  • Imperative mood: "add" not "added" — reads as an instruction, not a history log
  • No capital letter, no trailing period — enforces uniform parsing by changelog tools
  • Body separated by blank line — parsers split header/body at the first blank line
  • Breaking changes: use ! after type/scope, or add BREAKING CHANGE: footer (triggers MAJOR bump) — body-only descriptions are invisible to changelog tools
  • revert commits SHOULD include This reverts commit <hash>. in the body — git revert generates this automatically; don't strip it
  • NEVER add a Claude signature, AI agent attribution, or Co-authored-by trailer for Claude or any other AI agent to commits

Examples:

feat(auth): add JWT token refresh
fix: prevent race condition on concurrent requests

Introduce request ID and reference to latest request.
Dismiss responses from stale requests.
refactor!: drop support for Go 1.18

BREAKING CHANGE: Go 1.18 no longer supported; uses stdlib APIs from 1.21+

Closing Issues via Commit Messages

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:

fix(auth): prevent token expiry race condition

Closes #42
Closes owner/repo#99
  • Triggers when merged into the default branch (usually main)
  • Cross-repo: Closes owner/repo#42
  • Close multiple: Closes #42, closes #43
  • Works in PR descriptions too

GitLab:

feat: add dark mode support

Resolves #101
Closes group/project#42
  • Triggers when merged into the default branch (configurable per project)
  • Cross-project: Closes group/project#42
  • Close multiple: Closes #101, closes #102
  • Works in MR descriptions too

Tip: Pair with the commit type — fix: closing a bug issue, feat: closing a feature request — keeps the changelog semantically coherent.

Common Mistakes

MistakeFix
feat: Added login pagefeat: add login page — imperative, no capital
fix: fix bug.fix: fix bug — no trailing period
Subject over 72 charsShorten; move detail to body
Breaking change only in bodyAdd ! or BREAKING CHANGE: footer — tools won't detect body-only
feat(adding-auth): ...feat(auth): ... — scope is a noun, not a verb
Closes #42 in subject lineMove to footer — keeps subject clean and parseable

Best Practices

  • Align branch type and commit type — feat/auth-* branch → feat(auth): commits
  • One concern per branch — mixing fixes into feature branches obscures the changelog
  • Use scope consistently within a branch — feat(auth): throughout, not feat(user): mid-way
  • Squash merge: when squash-merging a PR/MR, the branch commits are collapsed into one — the PR/MR title becomes the commit message. If the title doesn't follow conventional commits format, changelog generation breaks silently. Always set the PR title before squashing.

來自 samber 的更多技能

golang-code-style
samber
Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments help vs hurt. Use when writing or reviewing Go code, asking about style or clarity, or establishing project coding standards. Not for naming conventions (→ See `samber/cc-skills-golang@golang-naming` skill), linter configuration (→ See `samber/cc-skills-golang@golang-lint` skill), or doc comments (→ See `samber/cc-skills-golang@golang-documentation` skill).
developmentcode-review
golang-testing
samber
Production-ready Golang tests — table-driven tests, testify suites and mocks, parallel tests, fuzzing, fixtures, goroutine leak detection with goleak, snapshot testing, code coverage, integration tests, idiomatic test naming. Use when writing or reviewing Go tests, choosing a testing approach, setting up Go test CI, or debugging flaky/slow tests. For testify-specific APIs see `samber/cc-skills-golang@golang-stretchr-testify`; for measurement methodology see...
developmenttestingcode-review
golang-design-patterns
samber
符合慣例的 Golang 設計模式 — 函數選項、建構子、錯誤流程與串聯、資源管理與生命週期、優雅關閉、韌性、架構、依賴注入、資料處理、串流等。適用於明確選擇架構模式、實作函數選項、設計建構子 API、設定優雅關閉、應用韌性模式,或詢問哪種慣用 Go 模式適合特定問題時。
developmentdesigncode-review
golang-error-handling
samber
Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log aggregation 3rd-party tools. Apply when creating, wrapping, inspecting, or logging errors in Go code. For samber/oops specifics → See `samber/cc-skills-golang@golang-samber-oops`...
developmentcode-review
golang-performance
samber
Golang 性能優化模式與方法論 - 若遇到 X 瓶頸,則應用 Y。涵蓋減少分配、CPU 效率、記憶體佈局、GC 調校、池化、快取以及熱路徑優化。適用於當性能分析或基準測試已識別出瓶頸,且需要正確的優化模式來解決時。亦適用於進行性能代碼審查時,提出改進建議或可協助快速識別性能增益的基準測試。不適用於測量方法論(→...
developmentcode-review
golang-security
samber
Golang的安全最佳實踐與漏洞防範。涵蓋注入攻擊(SQL、命令、XSS)、密碼學、檔案系統安全、網路安全、Cookie、機密管理、記憶體安全及日誌記錄。適用於撰寫、審查或稽核Go程式碼的安全性,或處理涉及加密、I/O、機密管理、使用者輸入處理或身分驗證的高風險程式碼。包含安全工具的配置。
securitycode-reviewdevelopment
golang-database
samber
Go 資料庫存取的全面指南 — 參數化查詢、結構掃描、可空欄位、交易、隔離層級、SELECT FOR UPDATE、連線池、批次處理、上下文傳遞與遷移工具。適用於撰寫、審查或除錯與 PostgreSQL、MariaDB、MySQL 或 SQLite 互動的 Golang 程式碼;資料庫測試;或關於 database/sql、sqlx 或 pgx 的問題。不產生資料庫結構或遷移 SQL。
developmentdatabase
golang-lint
samber
針對 Golang 專案的 lint 最佳實務與 golangci-lint 配置 — 執行 linter、設定 .golangci.yml、使用 nolint 指令抑制警告、解讀 lint 輸出,以及選擇 linter。適用於配置 golangci-lint、詢問 lint 警告或 nolint 抑制方式、設定程式碼品質工具,或挑選 linter 時。亦適用於使用者提及 golangci-lint、go vet、staticcheck 或 revive 時。
developmentcode-reviewtesting