SlideShare a Scribd company logo
團隊合作
Git tips and flow
Bo-Yi Wu
2016.04.21
1
關於我
http://blog.wu-boy.com/
https://github.com/appleboy
https://www.facebook.com/appleboy46
2
大綱
• Git 工作流程介紹
• Git 使用法則及小技巧
3
先來看看團隊開發流程
4
5
1.Develop
2. Pull
Request
3. Code
Review
4. Deploy
Git flow
早先 Git 開發模式
6
7
Main Branch
• Develop
– 最新的開發分支
• Master
– Production 專屬分支
8
Support branch
• Feature
– 開發新功能,從 develop 分支出來,完成後 merge 回
develop
• Release
– 準備 release 版本,從 develop 分支出來,只修 bugs,
完成後 merge 回 develop 和 master
• Hotfix
– 重大 bugs 修復,從 master 分支出來,完成後 Merge
回 develop 和 master 9
Git flow 詳細流程可以參考
https://goo.gl/XIThFY
10
有沒有覺得好多 Branch
搞得好複雜
11
Create branch
• Master
• Develop
• Feature
Merge Branch
• Master
• Develop
Code Conflict
• Master
• Develop
該從哪邊拉 branch 要 merge 回哪個 branch 要解決多次相同 Conflict
12
對團隊來說
• 開發者不易瞭解整個 Git flow
• 開發者不知道從哪個 Branch 繼續開發
• 開發完成後該 merge 回 master 或
develop?
• 需要解決多次衝突 (Merge 回多個分支)
13
PM: 那個新功能沒上 Production
RD: 抱歉忘記 Merge 回 Master
(回去檢查看看是不是忘記 Merge?)
14
搞得好複雜
技術主管管理不易
15
Github Flow
16
只有一個 Branch 叫 Master
不需要知道其他 Branch 作用
因為最終都會合併到 Master 分支
17
Github 流程
• 開發都從 master branch 開分支
• 隨時都可以發 Pull Request
• Review 過的 Pull Request 才可以 Merge
• 隨時都可以發佈新版本
18
Github Flow 優勢
• 只需要維護 Master 分支
– 禁止任何開發者使用 git push origin master –f
– 請將 master 設定無法使用 –f 覆蓋
• 開發者容易理解及學習
• 管理者方便 Code Review 及發佈新版
– 不用再擔心少 Merge branch
– 不用再擔心開發人員玩壞 branch
19
20
21
1.Develop
2. Pull
Request
3. Code
Review
4. Deploy
Github Flow 快速上版
該如何制訂 Production 編號
請善用 git tag 來 release production
22
上 Hotfix 版本
Tag 上 production
• git checkout –b hotfix 1.0.0
• git commit –a –m ‘xxxx’
• git tag –a 1.0.1 –m ‘1.0.1’
• git checkout master
• git cherry-pick commit-id
Master 上 production
• git commit –a –m ‘xxxx’
• git tag –a 1.0.1 –m ‘1.0.1’
23
24
Tag 1.0.0
Patch-1
Tag 1.0.1
Patch-1
Commit C
Commit A
Commit B
Tag 上 production
git cherry-pick patch-1
團隊 Git 使用法則
25
Git commit
• 標題不要過長 (請勿超過 50 字元)
• 標題請務必連結上 Issue Track System
– jira, github, redmine… 等
• 內容請補上 What, Why and How
– 或者是在 Issue Track 上描述清楚
• 不要紀錄無關緊要的 commit
– 像是 fix typo, update readme … 等
26
27
Assign
Issue
Create
Branch
Fix
issue
Code
Review
Testing
為什麼要 Code Review
• 降低 Production 出包機率
• 可以學習 coder 為什麼要這樣寫
• 可以學習 reviewer 會怎麼建議
• 團隊素質水準提高
28
29
Fix Issue
Code
Review
Fix Issue
Code
Review
Fix issue
git commit –a –m ‘fix typo’
git commit –a –m ‘update readme’
git commit –a –m ‘fix typo’
Git log
• git commit –a –m ‘fix typo 1’
• git commit –a –m ‘fix typo 2’
• git commit –a –m ‘fix typo 3’
• git commit –a –m ‘fix typo 4’
• git commit –a –m ‘fix typo 5’
• git commit –a –m ‘fix typo 6’
30
31
https://github.com/h5bp/Front-end-Developer-Interview-
Questions/pull/241/commits
Merge 到 Master 分支前
請務必 squash your commit.
32
Two way to squash your commit
• Git reset (一般用法)
• Git rebase (進階用法)
33
git reset
• git reset --soft HEAD^
– 合併多個 commit
– 修改上一個 commit message
• git reset --hard HEAD^ (小心使用)
– 回復到上一個 commit 狀態
– 這次修改,但是尚未 commit 的更動會消失
34
Demo
35
git rebase –i commitID
-i 互動模式
36
37
38
整理完 commit log 後
請把 master merge 到您的 branch
39
Two way to merge master
• git merge master
• git rebase master
40
41
git log --date-order
42
git log --topo-order
43
好處是確保你的 commit
保持在 Log 最上面
之後追 commit log 會比較好找
44
更新目前 branch 到最新
git pull --rebase origin master
45
Demo
46
Git diff 好工具
diff-so-fancy
https://github.com/so-fancy/diff-so-fancy
47
48
Git tips
49
救回已經 commit 的程式碼
git reflog
50
51
Any Question?
52

More Related Content

PDF
Understanding Branching and Merging in Git
PDF
GITS Class #16: CI/CD (Continuous Integration & Continuous Deployment) with G...
PDF
Using GitLab CI
PDF
Trunk-Based Development and Toggling
PPTX
Git hub ppt presentation
PDF
Hyperloglog Project
PDF
Continuous Integration/Deployment with Gitlab CI
PPTX
Depreme karşı dayanıklı binalar
Understanding Branching and Merging in Git
GITS Class #16: CI/CD (Continuous Integration & Continuous Deployment) with G...
Using GitLab CI
Trunk-Based Development and Toggling
Git hub ppt presentation
Hyperloglog Project
Continuous Integration/Deployment with Gitlab CI
Depreme karşı dayanıklı binalar

Viewers also liked (17)

KEY
Git branching-model
PDF
啟動 Laravel 與環境設定
PDF
CRUD 綜合運用
PDF
Route 路由控制
PDF
Composer 套件管理
PDF
使用者認證
PDF
開發環境建置
PDF
Model 設定與 Seeding
PDF
驗證與訊息
PDF
Migrations 與 Schema 操作
PDF
Eloquent ORM
PDF
Package 安裝與使用
PDF
整合 Open ID
PDF
PHP 語法基礎與物件導向
PDF
工作坊簡介
PDF
View 與 Blade 樣板引擎
PDF
使用 Controller
Git branching-model
啟動 Laravel 與環境設定
CRUD 綜合運用
Route 路由控制
Composer 套件管理
使用者認證
開發環境建置
Model 設定與 Seeding
驗證與訊息
Migrations 與 Schema 操作
Eloquent ORM
Package 安裝與使用
整合 Open ID
PHP 語法基礎與物件導向
工作坊簡介
View 與 Blade 樣板引擎
使用 Controller
Ad

Similar to Git flow 與團隊合作 (20)

PPTX
Git基礎介紹
PDF
Git 版本控制系統 -- 從微觀到宏觀
ODP
Git 教學
PDF
Introduction to git
PDF
如何與 Git 優雅地在樹上唱歌
PDF
Git in a nutshell
PDF
Intro to Git 投影片
PDF
Git 經驗分享
PPTX
Git & git hub v1.2
PDF
Git Tutorial
PPTX
Git & git flow
PDF
Git tutorial for windows user (給 Windows user 的 Git 教學)
PDF
COSCUP 2015 開源之道-Git工作坊教學簡報
PPTX
Git and git hub
PDF
連哈秋都懂的Git教學
PDF
GDSC Lecture - 與大家合作做專案之前必學_ Git 指令與觀念.pdf
PPT
Git簡報
PPTX
GIT實務操作與理論
PPTX
大家應該都要會的工具 Git 從放棄到會用2-分支篇
ODP
Git 程式碼版本控制軟體介紹
Git基礎介紹
Git 版本控制系統 -- 從微觀到宏觀
Git 教學
Introduction to git
如何與 Git 優雅地在樹上唱歌
Git in a nutshell
Intro to Git 投影片
Git 經驗分享
Git & git hub v1.2
Git Tutorial
Git & git flow
Git tutorial for windows user (給 Windows user 的 Git 教學)
COSCUP 2015 開源之道-Git工作坊教學簡報
Git and git hub
連哈秋都懂的Git教學
GDSC Lecture - 與大家合作做專案之前必學_ Git 指令與觀念.pdf
Git簡報
GIT實務操作與理論
大家應該都要會的工具 Git 從放棄到會用2-分支篇
Git 程式碼版本控制軟體介紹
Ad

More from Bo-Yi Wu (20)

PDF
Drone CI/CD 自動化測試及部署
PDF
用 Go 語言打造多台機器 Scale 架構
PDF
Job Queue in Golang
PDF
Golang Project Layout and Practice
PDF
Introduction to GitHub Actions
PDF
Drone 1.0 Feature
PDF
Drone CI/CD Platform
PDF
GraphQL IN Golang
PPTX
Go 語言基礎簡介
PPTX
drone continuous Integration
PPTX
Gorush: A push notification server written in Go
PPTX
用 Drone 打造 輕量級容器持續交付平台
PPTX
用 Go 語言 打造微服務架構
PPTX
Introduction to Gitea with Drone
PDF
運用 Docker 整合 Laravel 提升團隊開發效率
PDF
用 Go 語言實戰 Push Notification 服務
PPTX
用 Go 語言打造 DevOps Bot
PPTX
A painless self-hosted Git service: Gitea
PPTX
Write microservice in golang
PPTX
用 Docker 改善團隊合作模式
Drone CI/CD 自動化測試及部署
用 Go 語言打造多台機器 Scale 架構
Job Queue in Golang
Golang Project Layout and Practice
Introduction to GitHub Actions
Drone 1.0 Feature
Drone CI/CD Platform
GraphQL IN Golang
Go 語言基礎簡介
drone continuous Integration
Gorush: A push notification server written in Go
用 Drone 打造 輕量級容器持續交付平台
用 Go 語言 打造微服務架構
Introduction to Gitea with Drone
運用 Docker 整合 Laravel 提升團隊開發效率
用 Go 語言實戰 Push Notification 服務
用 Go 語言打造 DevOps Bot
A painless self-hosted Git service: Gitea
Write microservice in golang
用 Docker 改善團隊合作模式

Git flow 與團隊合作