技术控

    今日:0| 主题:63445
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Push to production three times faster with the right git workflow

[复制链接]
别碰我D人 发表于 2016-9-30 17:26:18
236 4
On the project I work, we needed to deploy in production several times a day, for business purposes, but the deployments took one and half hours. Indeed, we are several teams working along with the Scrum methodology, so our product owners are validating all our work. Thus we spent two thirds of our time to identify and isolate what has actually been validated and is ready to go in production.
   We created a new git workflow, inspired by the article A successful Git branching model , and adapted to the Scrum methodology. It helped us to organise our deployment process and to reduce our deployment time to 30 minutes.
   

Push to production three times faster with the right git workflow

Push to production three times faster with the right git workflow

  Our workflow is composed by 3 main branches :
  
       
  • The develop branch can be seen as the Truth : every line of code has been tested and validated by the client.   
  • The staging branch corresponds to the validation environment.   
  • The release branch contains the last version of your website in production.   
  • The feature branches are temporary.  
  The Git journey of a simple feature

  Let’s assume Alice and Bob develop an e-commerce website and she needs to register the shipping address of her customers. This feature could be splitting into 3 user-stories : adding a shipping address, editing it and removing it. All the three tickets are in the Sprint Backlog.
  She starts with the first user story, adding an address. The corresponding ticket is now in the Doing Column.
  1. git checkout develop && git pull origin/develop
  2. // She creates a new feature branch and a new user story one
  3. git checkout -b feature/shipping-address
  4. git checkout -b add-address
  5. // She codes and commits
复制代码
  

Push to production three times faster with the right git workflow

Push to production three times faster with the right git workflow

  In the meantime, Bob wants to help Alice and starts coding the address deletion.
  1. // He pulls the last version of the shared branch
  2. git checkout feature/shipping-address
  3. git pull origin/feature/shipping-address
  4. // He creates a new branch for the user story
  5. git checkout -b delete-address
  6. // He codes and commits
复制代码
  

Push to production three times faster with the right git workflow

Push to production three times faster with the right git workflow

  Alice finally finishes her feature locally, she puts the ticket into Code Review.
  1. // She pushes her code to the staging branch
  2. git push origin add-address
  3. // She opens a pull request with the staging environment
  4. git request-pull staging add-address
复制代码
Once Bob has reviewed her code, she can merge her branch into staging. The ticket is now in the Validation column, waiting for the Product Owner validation.
  1. // She gets the last version of the staging branch
  2. git checkout staging && git pull origin/staging
  3. git merge add-address && git push origin staging
  4. // She builds the validation environment
  5. // and asks the product owner to validate
复制代码
  

Push to production three times faster with the right git workflow

Push to production three times faster with the right git workflow

  The product owner has validated Alice’s work, the ticket finally in the Done column. She merge her work into the feature branch and starts another user story.
  1. // She pulls the last version of the feature branch
  2. git checkout feature/shipping-address
  3. git pull origin feature/shipping-address
  4. git merge add-address && git push origin feature/shipping-address
复制代码
When the whole feature has been validated by the client, Alice merges the feature branch into develop, as it’s ready to go into production.
  1. // She gets the last version of the develop branch
  2. git checkout develop && git pull origin/develop
  3. git merge feature/shipping-address && git push origin develop
复制代码
  

Push to production three times faster with the right git workflow

Push to production three times faster with the right git workflow

  At the end of the day, when they want to deploy into production, Bob merges develop into release and launches the deployment without any concern. Indeed he knows that all the code on develop is correct. He tags the commit of the release to get the history of each version.
  1. // He gets the last version of the develop and release branches
  2. git checkout develop && git pull origin/develop
  3. git checkout release && git pull origin/release
  4. git merge develop && git tag 2.1
  5. git push origin release --tags
复制代码
  

Push to production three times faster with the right git workflow

Push to production three times faster with the right git workflow

  The four rules of this workflow

  This workflow can seem to be heavy but after few days you become use to it.
  Nevertheless, you have to remember four rules:
  
       
  • Be strict : no inopportune commit on develop and not staging.   
  • Stay tuned : a feature is not done anymore right after the product owner validation, you need to merge your branch into develop to prepare the next release.   
  • Be clean : as it can drift apart, you should clean the staging repository every week. You should delete the staging branch, locally and remotely, and recreate it from develop :
    1. git co develop && git pull origin/develop
    2. git branch -d qual && git push origin --delete qual
    3. git co -b qual && git pull origin qual
    复制代码
      
  • Divide and Conquer : two features should be really distinct. Either they don’t use the same part of the code, either they are not developed at the same time.Yet, some conflicts could still happen between two user story branches, don’t panic. Let’s take an example. Alice and Bob have both added a translation at the same line in the translation file. Bob have merged his branch into staging before Alice, thus when she want to push she has conflicts with staging. What she could do is to pull the staging branch, merge her branch into it. Then she had to resolve the conflicts and my advice is to do it with Ben to address them together. Then she can push the merge branch to staging :
    1. git co qual && git pull origin/qual
    2. git merge alices-branch
    3. // Resolving conflicts
    4. git commit
    5. git push origin qual
    复制代码

   Post Views: 29
  You liked this article? You'd probably be a good match for our ever-growing tech team at Theodo.
     Join Us
落叶、锁秋 发表于 2016-9-30 18:50:45
前排支持下
回复 支持 反对

使用道具 举报

outinloowly 发表于 2016-10-1 23:16:59
我要让全世界知道这回帖被谁承包了
回复 支持 反对

使用道具 举报

落幕後得哀傷 发表于 2016-11-2 06:15:26
路过 帮顶 嘿嘿
回复 支持 反对

使用道具 举报

kingwin2014 发表于 2016-11-4 14:35:07
别碰我D人人气很旺!
回复 支持 反对

使用道具 举报

我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/c.CoLaBug.com ( 粤ICP备05003221号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表