Branching Strategy - nycu-xuan/FastShop GitHub Wiki
main
, develope
, frontend
, backend
, feature
, hotfix
/-> feature
/-> hotfix /-> frontend
main -> develope
\-> backend
\-> feature
以下 branch 會一直存在 (they should be protected)
main
develope
frontend
backend
啟用的分支保護設定 (click to expand):所有併入 main
與 develope
的動作都必須經過 pull request 和 2 位以上的 reviewer approve。
結束了一個週期的 frontend
或 backend
功能開發之後會併入 develope
,進行整合測試,當通過後達成 release 的標準,才可併入 main
,並將 major 或 minor 編號加 1。
當每次決定下一個週期要完成的 feature 之後,我們在 GitHub Issues 上新增一個 feature list 條列這些功能,而後frontend
和 backend
會將 develope
併入以取得最新狀態,各自帶開進行開發。
$ git checkout frontend
$ git merge --no-ff develope
當此週期的 feature list 上的項目都完成,且通過 CI checks,我們稱「此週期開發結束」(前後端分開),併入 develope
。
$ git checkout develope
$ git merge --no-ff frontend
我們用 GitHub Issues 來 track 我們的 work in progress。
從 feature list 中挑選一個 feature,然後開一個新的 issue 來描述其細節,接著根據其是前或後端來選擇他從哪個 branch 切出。 假設要新增「商品搜尋」,其細節應該包含前後端各自需實作的內容並進一步標號:
Issue #10
- 1. 新增搜尋欄 (frontend)
- 2. 新增對資料庫的
SELECT
SQL (backend) - 3. 提供搜尋 api (backend)
feature 分支的命名:{issue number}-{sub issue number}-{feature description}
則在新增對資料庫的 SELECT
SQL 時,應從 backend
切出 10-2-support-select-sql backend
。
$ git checkout -b 10-2-support-select-sql backend
當 feature 開發完成且通過 CI checks 後,即可提出 pull request,並設定讓對應的 issue 在此 PR 成功併入後 close。
須經過 1 位 reviewer approve 後才可併入對應的前後端分支。
$ git checkout frontend
$ git merge --no-ff 10-add-search-bar
hotfix 分支的命名:hotfix-{issue number}-{hotfix description}
當 release 的版本出現問題,在發出 issue 後直接從 main
切出 hotfix
分支。
git checkout -b hotfix-11-fix-broken-api main
修復完成後,此 hotfix
須併入 main
,並將 patch 編號加 1 ,同時也併入 develope
, frontend
及 backend
,來反映給開發中的分支。
$ git checkout main
$ git merge --no-ff hotfix-11-fix-broken-api
$ git checkout frontend
$ git merge --no-ff hotfix-11-fix-broken-api
$ git checkout backend
$ git merge --no-ff hotfix-11-fix-broken-api
$ git branch -d hotfix-11-fix-broken-api
若要調整建置程序、引入新的工具或重構等不相關於 feature 的修改,可在提出 issue 後,依照其作用層級直接從 develope
, frontend
, backend
切出,其命名為 {issue number}-{description}
。這類分支的合併規範同其母分支。
依照功能的需要在開發時切出的小分支。此類分支不必須要有 issue 或 PR,也不強制 review。可使用 sqaush
merge。
$ git checkout refactor-sql-class 10-2-support-select-sql
$ git checkout 10-2-support-select-sql
$ git merge --squash refactor-sql-class