Gitworkflow

Gitworkflow is 指团队 in usingGitforversion控制时遵循 一套标准化流程, includingbranchmanagement, codesubmitting, code审查, merge策略etc.. 选择合适 workflow for 于improving团队协作efficiency, 保证codequality and 加速release流程至关 important .

1. Gitworkflow important 性

一个良 good Gitworkflow可以带来以 under good 处:

2. common Gitworkflowmodel

目 before has many 种流行 Gitworkflowmodel, 每种model都 has 其Pros and Cons and 适用场景.

2.1 Git Flow

Git Flow is 由Vincent Driessen提出 一种经典 Gitworkflow, 它定义了严格 branchmodel, 适用于 has 明确version计划 project.

2.1.1 branchstructure

2.1.2 workflow程

  1. from developbranchcreationfeaturebranchDevelopment new functions.
  2. functionsDevelopmentcompletion after , mergefeaturebranch回developbranch.
  3. 准备release时, from developbranchcreationreleasebranch.
  4. in releasebranch on fortest and bug修复.
  5. releasecompletion after , 将releasebranchmerge回master and developbranch, 并 in masterbranch on 打tag.
  6. such as果已releaseversion出现bug, from masterbranchcreationhotfixbranchfor修复.
  7. 修复completion after , 将hotfixbranchmerge回master and developbranch, 并 in masterbranch on 打tag.

2.1.3 Pros and Cons

优点:

缺点:

2.1.4 适用场景

适合 has 明确version计划, release周期较 long big 型project, such as桌面application, 传统软件etc..

2.2 GitHub Flow

GitHub Flow is GitHub提出 一种 simple Gitworkflow, 它强调持续deployment, 适用于 fast 速iteration project.

2.2.1 branchstructure

2.2.2 workflow程

  1. from masterbranchcreationfeaturebranch.
  2. in featurebranch on forDevelopment, 频繁submitting.
  3. 将featurebranchpush to 远程仓library.
  4. creationPull Request, 邀请team membersforcode审查.
  5. 根据code审查意见formodify.
  6. 审查through after , 将featurebranchmerge回masterbranch.
  7. masterbranchmerge after 自动deployment.

2.2.3 Pros and Cons

优点:

缺点:

2.2.4 适用场景

适合 fast 速iteration, continuous delivery project, such asWebapplication, SaaS产品etc..

2.3 GitLab Flow

GitLab Flow is GitLab提出 一种workflow, 它结合了Git Flow and GitHub Flow 优点, supportcontinuous delivery and environmentbranch.

2.3.1 branchstructure

2.3.2 workflow程

  1. from masterbranchcreationfeaturebranchDevelopment new functions.
  2. functionsDevelopmentcompletion after , mergefeaturebranch回masterbranch.
  3. 将masterbranchdeployment to testenvironmentfortest.
  4. testthrough after , 将masterbranchmerge to stagingenvironmentbranchfor预releasetest.
  5. 预releasetestthrough after , 将stagingbranchmerge to productionbranchfor正式release.
  6. for 于需要maintenance version, 可以creationreleasebranchformaintenance.

2.3.3 Pros and Cons

优点:

缺点:

2.3.4 适用场景

适合需要 many environmentdeployment, continuous delivery project, such as企业application, moveapplicationetc..

2.4 Trunk-Based Development (TBD)

Trunk-Based Development is a强调频繁集成 Gitworkflow, 所 has Development者都直接 in 主branch on 工作 or creation short 期 functionsbranch.

2.4.1 branchstructure

2.4.2 workflow程

  1. from trunkbranchcreation short 期functionsbranch (生命周期不超过几天) .
  2. in functionsbranch on forDevelopment, 频繁submitting.
  3. 每天至 few merge一次 to trunkbranch, or usingPull Requestforcode审查.
  4. merge before 必须through所 has automationtest.
  5. trunkbranch始终保持可deploymentstatus.
  6. usingfeatures标志 (Feature Flags) 控制 new functions release.

2.4.3 Pros and Cons

优点:

缺点:

2.4.4 适用场景

适合需要 fast 速iteration, continuous integration/continuous delivery project, such as互联网产品, SaaSserviceetc..

3. workflow 选择因素

选择合适 Gitworkflow需要考虑以 under 因素:

4. workflowbest practices

无论选择哪种workflow, 以 under best practices都 has 助于improving团队 协作efficiency and codequality:

实践case: usingGitHub FlowforDevelopment

  1. from masterbranchcreation一个 new featurebranch: git checkout -b feature-login
  2. in featurebranch on Developmentloginfunctions, 频繁submitting: git add . && git submitting -m "Add login form"
  3. 将featurebranchpush to 远程仓library: git push -u origin feature-login
  4. in GitHub/GitLab on creationPull Request, 邀请team membersforcode审查
  5. 根据code审查意见formodify, 并再次submitting: git add . && git submitting -m "Fix login validation" && git push
  6. 审查through after , 将featurebranchmerge to masterbranch
  7. delete本地 and 远程 featurebranch: git branch -d feature-login && git push origin --delete feature-login
  8. from masterbranchpull最 new code: git checkout master && git pull

互动练习

请completion以 under 练习, 巩固Gitworkflow understanding:

  1. 选择一个你熟悉 project, analysis它适合using哪种Gitworkflow, 并说明原因.
  2. 根据GitHub Flow 流程, mock一个完整 functionsDevelopment过程, including:
    • creationfeaturebranch
    • for many 次submitting
    • push to 远程仓library
    • creationPull Request
    • merge to masterbranch
    • deletefeaturebranch
  3. 比较Git Flow and GitHub Flow Pros and Cons, 并说明它们各自适合 场景.
  4. 思考such as何 in Trunk-Based Developmentinmanagement一个需要 long 期Development big 型functions.
  5. 制定一份适合你团队 Gitworkflow规范, includingbranch命名, submitting规范, code审查流程etc..

completion练习 after , 你应该able to熟练Master不同Gitworkflow 特点 and 适用场景, 并able to选择适合自己project workflow!