Branching Strategy - nycu-xuan/FastShop GitHub Wiki

main, develope, frontend, backend, feature, hotfix

                            /-> feature
  /-> hotfix    /-> frontend 
main -> develope 
                \-> backend
                            \-> feature

Main branches

以下 branch 會一直存在 (they should be protected)

  • main
  • develope
  • frontend
  • backend
啟用的分支保護設定 (click to expand):所有併入 maindevelope 的動作都必須經過 pull request 和 2 位以上的 reviewer approve。

the settings page of branch protection

結束了一個週期的 frontendbackend 功能開發之後會併入 develope,進行整合測試,當通過後達成 release 的標準,才可併入 main,並將 major 或 minor 編號加 1。

Development branches

開始新的開發週期

當每次決定下一個週期要完成的 feature 之後,我們在 GitHub Issues 上新增一個 feature list 條列這些功能,而後frontendbackend 會將 develope 併入以取得最新狀態,各自帶開進行開發。

$ git checkout frontend
$ git merge --no-ff develope

結束開發週期

當此週期的 feature list 上的項目都完成,且通過 CI checks,我們稱「此週期開發結束」(前後端分開),併入 develope

$ git checkout develope
$ git merge --no-ff frontend

Supporting branches

我們用 GitHub Issues 來 track 我們的 work in progress。

Feature branches

開始開發一個新功能

從 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 branches

hotfix 分支的命名:hotfix-{issue number}-{hotfix description}

當 release 的版本出現問題,在發出 issue 後直接從 main 切出 hotfix 分支。

git checkout -b hotfix-11-fix-broken-api main

修復完成後,此 hotfix 須併入 main,並將 patch 編號加 1 ,同時也併入 develope, frontendbackend,來反映給開發中的分支。

$ 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

Other branches

非功能性修改的 branches

若要調整建置程序、引入新的工具或重構等不相關於 feature 的修改,可在提出 issue 後,依照其作用層級直接從 develope, frontend, backend 切出,其命名為 {issue number}-{description}。這類分支的合併規範同其母分支。

Branch of feature branches

依照功能的需要在開發時切出的小分支。此類分支不必須要有 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

參考自 A successful git branching model

⚠️ **GitHub.com Fallback** ⚠️