Top Banner
Let’s your collaborators more happy with GitFlow
13

Let’s your collaborators more happy with git flow

Feb 13, 2017

Download

Nguyen Binh Son
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Lets your collaborators more happy with GitFlow

tt c nhng s khc nhau gia git vi cc cvs khc, tt c nhng cng c hon ton mi l, nhng khi nim m dng nh ch git mi c, v.v.. u c thit k cho mt mc ch duy nht: lm cho git fit" cc k vi mong mun lm vic phn tn, ni d hiu hn, th l lm cho vic cng tc tr nn t do hn.

nu coi git l mt ngn ng, th c rt nhiu thut ton c th c sinh ra gii quyt cng mt bi ton cng tc .

trong phn ny, chng ta ng qua mt vi dng thut ton ln vn thng c p dng trin khai. tt c nhng thut ton" ny c tn gi chung l cc git workflows. bt c mt d n git no cng cn phi c mt git flow bm theo, nu khng mi th s tr thnh mt th bng bong. v mi orkflow u ri s chun ho thnh mt trong s cc flow trong bi ny.

Hiu, p dng v sng to ra cch x l vi git flows gip lp trnh vin cng tc vi nhau tt hn.

Centrallize Workflow

Bt u vi basic workflow - lung lm vic c trung tm"

Centrallize Workflow (2)

Lung n gin nht, d nm bt nht, d tng tng nht c bit l vi cc nhm mi chuyn t svn sang. Lung ny c th coi nh l mt kiu p lung dng svn sang git", ta khng cn quan tm/thm ch khng cn bit n nhnh, ch vic dng nhnh default l master.

Centrallize Workflow (3)

Tuy nhin, c im ca git l commit c contr cha" rt r rng, nn khi lm vic nhm th thng xuyn xy ra s r nhnh, lc ny m push th git s khng cho v mun g th mun mnh vn phi pull, v lc pull th n s i merge, v cy lch s s khng tuyn tnh na.

Lm th no by gi?

Centrallize Workflow (4)

Mun khng phi merge, ni cch khc l mun gi cy c thng, th n merge ra v dng rebase.

Mun gi cy lich s c thng, ta s dng chin thut rebase. C th l ta s lun pull --rebase - v s c kt qu y ht nh svn - commit ca mnh s cui cng. Sau push. Nu lc ny mnh li tip tc b bddd th ch vieecj li pull tip.

Centrallize Workflow (5)

Nu lc pull --rebase c conflict - s vic xy ra s ging y nh bi ton merge - tin trnh rebase s b stop ti commit gy ra conflict, ta x l conflict, xong add, tuy nhin bc cui cng thay v commit th ta chy git rebase --continue tip tc rebase. L do m c c --continue y l, cho d sau khi add xong th tin trnh rebase vn cha kt thc, vn cn nhiu commit pha sau cha c copy, v cha hn l cc commit khng tip tc xy ra conflict, cho nn tin trnh rebase mi c thit k nh th.

vic pull -rebase c th xy ra nguyn mt chui conflict v mnh s phi lm ln lt tng ci mt - chuyn l bnh thng.

Nu lc no khng chu ni na, v mun p i pull li th c th dng git rebase --abort

Sau khi rebase xong th c th squash cc commit trc khi push, vic y m bo cho mi commit trn nhnh master l mt chc nng trn vn, kh p, tuy b mt lch s x l tng bc, nhng vic khng cho commit ca chc nng ny ln vo commit ca chc nng kia cn quan trng hn, nhng li ko theo nhc im tip theo l t khi mnh chy push c, m tt nht l nn code cho xong xui ri hng push, nhc im tip theo ti t vic hon thin business - nu nghip v thay i v i hi c thm code th vic commit b xen k vn s xy ra.

Feature Branch Workflow

Mun vn c lch s thay i, m vn mun push thognf xuyn, mun chnh sa nghip v ti khi kh chn th thi m nhnh master vn p, th bt buc ng phi tch nhnh, ri ng mun lm g th lm, y l c s ca workflow tip theo - mt s nng cp ca centrallize workflow, v sau khi hon thinj th n c t tn nh trn.

Quy lut cho workflow ny l: mi commit hon thin chc nng phi c thc hin trn nhnh. Nhnh c tch t master v c gi l feature-branch - vnext thi c th gi l issue-branch.

Pull request

y cng l workflow u tin m tn dng c chc nng pull-request, gip cho tt c nhng ngi tham gia vo d n c th trc tip quan st c nhng g ang xy ra v a ra kin m khng h c tr. p dng c pullrequest cng to tin cho vic a codereview vo mt phn ca quy trnh .

T tng ng sau pull request l: l mt notification thng bo cho nhng ngi c thm quyn trn branch nm trn bit rng ta mun h ng trn branch y v pull branch v.

Khng ch th, ci hay l pull request c th nm mt trong ba trng thi: vn ang ch, rejected, hoc accepted - chnh ba trng thi ny lm nn s lp la lp lnh ca pull request trong quy trnh lm vic cng tc.

Ch rng bn thn pull request khng phi l chc nng ca git, n l mt chc nng ca h thng qun l issue m thng c tch hp lun vo cc giao din web ca cc repo git u bng hin i. Thm ch cc h thng ny cn c kh nng cho php merge branch bng giao din web nu pull request c accept.

Cu chuyn ca pull request trong workflow ch l: ai, v lc no th pullrequest c accept hoc b reject m thi.

Feature Branch Workflow (2)

u tin, ng nhnh master, to nhnh v checkout sang hoc checkout -b. Ngay lp tc push -u push ref mi ln ng thi setup tracking branch.

Sau (code/push)(lp li). Ngon ri th dev to pull request, team tho lun, review, v tip tc code/push. Chn ch cho ti khi pull request c ngi review accept. Ti lc ny th c th merge, ai merge cng c.

Nu khng merge bng web th c th merge th cng:

Checkout sang master, pull.Merge origin/feature vo bng git merge hoc git pull.Nu c conflict th x l.Push ln master.

Gitflow Workflow

Feature Branch l mt flow rt tt, tht ra th bt c flow no s dng phn nhnh issue/pull request u tt c. Vn l i vi cc d n rc ri v mt hnh chnh, n cn c nng cp, feature branch c chia ra lm nhiu loi, master c chia ra lm nhiu loi. Merge qua nhiu tng, nhiu lp. y l tng c rt nhiu t chc s dng. Gitflow l mt trong cc kch bn nh th, v v mt l thuyt cng nh s dng thc t chng minh l n hiu qu.

tng v gitflow c th trnh by qua hnh trn. Trin khai thc t phc tp hn p ng cc tnh hung thc t. Nhng tng ct li l nh sau:

Tch bit nhnh master ra thnh develop v master. Tn nh ngha.Tch t nhnh dev ra mt loi nhnh ph tr cho nhnh dev l cc nhnh feature. Tt c cc commit b sung cho feature nht thit phi c thc hin trn nhnh feature. Mi commit i din cho mt bc tin trin ca feature.Nhnh feature sau khi c accept, s c merge vo nhnh develop, trn nhnh develop nht thit ch c cha cc commit merge t nhnh feature, nh vy th mi commit develop s i din cho mt ln tng chc nng.Vic accept nhnh feature l nhim v ni b ca teamdev.Nhnh feature mt khi merge ri th KHNG CODE TIP VO Y NA - v vic ny ph hng flow.

thun tin hn cho vic trin khai release, nhng rule sau c thm vo:

Nhng feature gp gp nht - tc l nhng feature ca bn release k tip s c merge vo develop trc, s khng c c feature no ca bn release tip theo c php merge cho n khi develop c y cc feature ca bn release gn nht. Cn ch , vic merge" y ch xy ra khi feature branch c accept - tc l review tesst tic cc kiu ri.Ngay khi nhnh develop c cc feature cho bn release gn nht, ta s tch t develop ra nhnh release_x.y.z. Sau khi c nhnh ny ri th c th tip tc merge cc feature gn gp gp nht.Sau khi to nhnh release th c th to pullrequest n nhnh master. S hin din ca pullrequest ny mang tnh thng bo cho b phn ng vai tr QA rng: bn dev hon thnh mt bn release, c th test c ri.Nhnh relaese c th c li, cc bugfixes c th c commit trc tip trn nhnh release ny. Tr khi c qu nhiu bug, nu khng th cy ca nhnh release thng l thng, ta c th gi n thng bng chin thut rebase, nh basic flow. Mi khi bug c sa, bugfix c th ngay lp tc c merge ngc vo nhnh develop.Khi nhanhs release c xc nhn l done, bn QA c th lm hnh ng l accept pullrequest, nu c h thng CI th ngay lp tc nhnh release s c merge vo nhnh master, TAG nh du phin bn s c gn vo commit merge, sourcecode s ngay lp tc c build, nu l web th bn build s ngay lp tc c deploy, nu khng c CI th nhng vic trn s c thc hin bng cm.K c sau khi release ri th li vn c th c pht hin, tuy nhin nh l nhnh c accept pull request v merge ri th khng code vo na, do cc li ny, c th s c a vo danh sch feature bn release sau, hoc c sa ngay lp tc bng cch to ra nhnh hotfix_xxxx t nhnh master, cu chuyn sau vi nhnh ny s hon ton ging vi nhnh release: to pull request sau khi xong, merge ngc thng xuyn vo nhnh dev, CI chy ngay sau khi accpeted.

Forking Workflow

y l mt flow c bit, khc hon ton vi cc flow k ra. Thc ra n c xy dng cho th gii phn mm ngun m. Nhng t tng ca n hon ton c th c p dng cho nhng d n c mi tng t: l khi gp kh khn trong vic qun l nhng ai c quyn push ln repo ny". Khng th m full quyn push i vi tt c member ca repo, nhng cng khng c hn ch cc member y cng tc pht trin.

Cc h thng repo hosting hin i vi chc nng to pull request c th h tr gii quyt vn ny.

User c th clone repo gc v, sau push ln chnh repo hosting nhng di thm quyn ca mnh. Vic y c gi l fork. User c th pht trin cc tnh nng mnh mun cng tc ln repo ca mnh. u ra l nhnh master repo ca mnh. Vic p dng flow no cho repo ca user do user quyt nh.

Ti lc no , user s to pull request t nhnh master ny ti nhnh no repo gc. Nhnh no th ph thuc vo flow ca repo gc. Vi opensource th mnh c th to thng tr vo nhnh master. Nhng nu l forking do nhng nguyn nhn khc th cha hn. Ni chung mnh s phi c contribution-note repo gc bit chuyn ny. Nu khng cn lu pull request mi c accept.

Out very own Workflow

Chng ta va do qua 4 trng phi chnh ca git workflow. Chng khng nht thit phi c p dng mt cch cng nhc, chng ch l cc nguyn mu, ni ln rng chng ta c th gii quyt vn cng tc bng nhng chiu nh no. Git cho php chng ta t do thit k m hnh fit nht vi tnh hung d n. Tt c cc mnh kho ca cc nguyn mu u c th kt hp rt nhuyn vi nhau. Tu bn sng to.