GitFlow
以下是非常經典的GitFlow
推薦閱讀
https://nvie.com/posts/a-successful-git-branching-model/
https://datasift.github.io/gitflow/IntroducingGitFlow.html
The main branches
生命週期: 無限
- master
- develop (integration branch)
master
基本上每個開發者local的master和origin/masterr=應該都是相同的
主要用來打Tag,這邊釋出的是正式Production Release
develop (integration branch)
所有開發異動都應該先整併到此分支(hotfix除外)
當確認develop的版本穩定且功能正確無誤,就可以經過release branch merge回master並押上release tag。
merge回master的部分會在release branch詳談。
Supporting branches
生命週期: 有限(當該branch merge回目標branch後,可以刪掉該branch)
- Feature branches
- Release branches
- Hotfix branches
Feature branches
Feature branches typically exist in developer repos only, not in origin.
建立新的branche
git checkout -b featureA develop
|
|
Release branches
作為develop merge 回 master的中間層,可以在這層準備meta-data(version number, build dates, etc.)
這樣develop層就很單純的專注在界接不同開發
因為這時候merge回master就等同於直接上版到正式環境了,所以應該特別注意。
也可以在master加上Git hook,讓develop merge回master時(也就是master有新的commit),執行script來做Unit Test、Automatically Build以及把我們的code roll-out到production server
Hotfix branches
緊急上版。
儘管merge進master時再怎麼小心,還是有可能出錯,這時候就需要緊急修復bug,而此時develop可能有經歷了很多commit異動,release branch也在merger回master後被刪除了,
所以這邊會從master緊急拉出Hotfix branch進行程式修復的動作,修復完成在merge回 master以及develop的部分
GitHubFlow
Git hook
client side 和server side
pre-hook 在指令執行前觸發,並可取消行為;post-hook 得是在指令結束後執行,它無法取消行為只能做其他自動化的設定。
備註
上述的Flow不是必要準則,還是要依據團隊來安排適合自己的流程較為適當。
Reference
https://stackoverflow.com/a/35915110
https://githubflow.github.io/
https://guides.github.com/introduction/flow/
https://git-scm.com/book/zh-tw/v2/Customizing-Git-Git-Hooks
https://gitbook.tw/chapters/gitflow/why-need-git-flow.html