Git Flow Step Note

Jayson Chiang
2 min readOct 29, 2021

筆記一下常用的 Git-Flow 指令集,需要時就無腦照抄

主線: master
發布支線: release
開發支線: develop
功能支線: feature (feature-xxx)
除錯支線: hotfix (hotfix-xxx)

masterdevelop 為長期存在的 Long-running branches,其餘均為階段性任務,用完就丟。

  1. 本機獨立開發新功能,開發完後合併回 develop
$ git checkout develop
$ git checkout -b feature-xxx

feature-xxx 開發完並 commit之後

$ git checkout develop$ git pull // 確保 develop 與遠端同步為最新狀態$ git merge feature-xxx
$ git push
$ git branch -d feature-xxx

2. 發布分支 ( 即把 develop合併到 master 交給 CI/CD )

$ git checkout develop
$ git checkout -b release
$ git checkout master
$ git merge release
$ git push
$ git checkout develop
$ git merge release
$ git push
$ git branch -d release

3. 當前功能具有歷史性階段,幫 master 加上 Tag 版號

$ git checkout master$ git tag -a 1.0.0 -m "Significant Milestone" master$ git push --tags

4. 發現需要緊急修正的 Bug

$ git checkout master
$ git checkout -b hotfix-xxx

hotfix-xxx debug 完並 commit

$ git checkout master
$ git merge hotfix-xxx
$ git push
$ git checkout develop
$ git merge hotfix-xxx
$ git push
$ git branch -d bugfix-xxx

--

--