---
title: Branch Naming Convention
tags: Git
---
# Branch Naming Convention
如何命名分支可以減輕開發者的負擔, 也能避免重複和不需要的開發成本
:::success
:# 命名取決於團隊協作的共識, 以下規則僅供參考的依據
:::
# Branch sample

# Reminder
1. Use ==issue tracker IDs== in branch names
- `hotfix-`, `feature-`, `chore-`
- 722-add-billing-module
- 720-submodules-rc
- 723-fix-highlighting
2. Add a ==short descriptor== of the task
- 適合不同開發者透過不同 branches 處理同一個問題
3. Use ==hyphens== as separators
- 也可以是 underscore _
4. Use ==group word==
- `BUG`: The bug which needs to be fixed soon
- `WIP`: The work is in progress, and I am aware it will not finish soon
- `bug-logo-alignment-issue` – the developer is trying to fix the logo alignment issue
- `wip-ioc-container-added` – the branch relates to the task to add an IoC container in progress.
- 可以與 tracker ID 搭配, 要注意 branch name 不宜過長, 以精簡可讀為主
- 搭配 1, 4: `wip-8712-add-testing-module`, 適合 fixing bugs
5. With ==author name==
- 適合針對人類
- `<author>_<branch-type>_<branch-name>`
- `jason_feature_check-user-list`
6. avoid using numbers only
7. avoid using all naming convention simultaneously
8. avoid long descriptive names for long-lived branches
9. slash `/` categorizes branch and tag
# Regular & Temporary Branches
## Regular Branch
### Development (dev)
- feature branches 的集成
- dev 是日常開發的分支
- 保持最新
- bugfix 之後合併至此
- 若需要對外發布會 merge 到 master
### Master (master)
- stable
- keep up-to-date
- Not allow checkout directly
- before merge with master, it must do code review
- 提供使用者使用的正式版本從 master 釋出
- 不能直接 checkout 修改
- 一般由 dev 和 hotfix 的合併
### QA (QA/test)
- QA testing
- automation testing
- 在 production 之前, 必須跑一次 QA testing
- 與 UT, IT 不同, 這裡主要是測試 scenario
## Temporary Branch
### bugfix
- 修正版本功能
- 從 master, dev 分出來
- 未來會合併進 dev 或 master
### hotfix
- 修正以已上線版本的功能
- 其實應該為 hotfixes, 通常會使用較短的 hotfix
- 通常是從 master 分出來, 而非 dev
### feature
- 開發單一功能
- 從 dev 分出來
- refactor 屬於此
:::danger
Adding a new prefix such as "refactoring" is problematic.
:::
-----------
### experimental
### WIP
- ongoing work
- 不會很快完成
### release
- 定期發佈的版本
- 合併到 master 之前的預釋出版本測試
- 從 dev 分出來
- 未來會合併進 dev 或 master
- 出問題可以提交 bugfix, 不用從 dev 重新發布 bugfix 後提交 release
### junk
- 可丟棄的分支
### try
- 新技術嘗試
- 不寫 issue, 不發 PR
# Issue
## branch naming of UnitTest vs unittest
建議小寫為主, 透過 `git push -d UnitTest` 刪除 UnitTest 分支
:::info
==Users should always consider that URLs are case-sensitive==
W3.org: https://www.w3.org/TR/WD-html40-970708/htmlweb.html
:::
# Further Reading
- Git Tips: https://hackmd.io/@brian-riversoft/SksHQo0yw
- Commit Tips: https://hackmd.io/@brian-riversoft/SkZ-Iehhd
# Appendix

# Reference
- https://codingsight.com/git-branching-naming-convention-best-practices/
- https://deepsource.io/blog/git-branch-naming-conventions/
- https://blog.alantsai.net/posts/2017/09/git-naming-for-repo-tag-and-branch-best-practice
- https://hackernoon.com/git-branch-naming-convention-7-best-practices-to-follow-1c2l33g2
- https://gist.github.com/digitaljhelms/4287848
- https://www.gushiciku.cn/pl/pF60/zh-tw
- http://josephlin.org/git-styleguide.html
- https://zhuanlan.zhihu.com/p/257857632