A place to cache linked articles (think custom and personal wayback machine)
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.md 16KB

před 5 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. title: GitHub Flow
  2. url: http://scottchacon.com/2011/08/31/github-flow.html
  3. hash_url: 5669f09e770c1bae1f4a84a753eff260
  4. <h2>Issues with git-flow</h2>
  5. <p>I travel all over the place teaching Git to people and nearly every class and workshop I’ve done recently has asked me what I think about <a href="http://nvie.com/posts/a-successful-git-branching-model/">git-flow</a>. I always answer that I think that it’s great - it has taken a system (Git) that has a million possible workflows and documented a well tested, flexible workflow that works for lots of developers in a fairly straightforward manner. It has become something of a standard so that developers can move between projects or companies and be familiar with this standardized workflow.</p>
  6. <p>However, it does have its issues. I have heard a number of opinions from people along the lines of not liking that new feature branches are started off of <code>develop</code> rather than <code>master</code>, or the way it handles hotfixes, but those are fairly minor.</p>
  7. <p>One of the bigger issues for me is that it’s more complicated than I think most developers and development teams actually require. It’s complicated enough that a big <a href="https://github.com/nvie/gitflow">helper script</a> was developed to help enforce the flow. Though this is cool, the issue is that it cannot be enforced in a Git GUI, only on the command line, so the only people who have to learn the complex workflow really well, because they have to do all the steps manually, are the same people who aren’t comfortable with the system enough to use it from the command line. This can be a huge problem.</p>
  8. <p>Both of these issues can be solved easily just by having a much more simplified process. At GitHub, we do not use git-flow. We use, and always have used, a much simpler Git workflow.</p>
  9. <p>Its simplicity gives it a number of advantages. One is that it’s easy for people to understand, which means they can pick it up quickly and they rarely if ever mess it up or have to undo steps they did wrong. Another is that we don’t need a wrapper script to help enforce it or follow it, so using GUIs and such are not a problem.</p>
  10. <h2>GitHub Flow</h2>
  11. <p>So, why don’t we use git-flow at GitHub? Well, the main issue is that we deploy all the time. The git-flow process is designed largely around the “release”. We don’t really have “releases” because we deploy to production every day - often several times a day. We can do so through our chat room robot, which is the same place our CI results are displayed. We try to make the process of testing and shipping as simple as possible so that every employee feels comfortable doing it.</p>
  12. <p>There are a number of advantages to deploying so regularly. If you deploy every few hours, it’s almost impossible to introduce large numbers of big bugs. Little issues can be introduced, but then they can be fixed and redeployed very quickly. Normally you would have to do a ‘hotfix’ or something outside of the normal process, but it’s simply part of our normal process - there is no difference in the GitHub flow between a hotfix and a very small feature.</p>
  13. <p>Another advantage of deploying all the time is the ability to quickly address issues of all kinds. We can respond to security issues that are brought to our attention or implement small but interesting feature requests incredibly quickly, yet we can use the exact same process to address those changes as we do to handle normal or even large feature development. It’s all the same process and it’s all very simple.</p>
  14. <h3>How We Do It</h3>
  15. <p>So, what is GitHub Flow?</p>
  16. <ul>
  17. <li>Anything in the <code>master</code> branch is deployable</li>
  18. <li>To work on something new, create a descriptively named branch off of <code>master</code> (ie: <code>new-oauth2-scopes</code>)</li>
  19. <li>Commit to that branch locally and regularly push your work to the same named branch on the server</li>
  20. <li>When you need feedback or help, or you think the branch is ready for merging, open a <a href="http://help.github.com/send-pull-requests/">pull request</a></li>
  21. <li>After someone else has reviewed and signed off on the feature, you can merge it into master</li>
  22. <li>Once it is merged and pushed to ‘master’, you can and <em>should</em> deploy immediately</li>
  23. </ul>
  24. <p>That is the entire flow. It is very simple, very effective and works for fairly large teams - GitHub is 35 employees now, maybe 15-20 of whom work on the same project (github.com) at the same time. I think that most development teams - groups that work on the same logical code at the same time which could produce conflicts - are around this size or smaller. Especially those that are progressive enough to be doing rapid and consistent deployments.</p>
  25. <p>So, let’s look at each of these steps in turn.</p>
  26. <h4>#1 - anything in the master branch is deployable</h4>
  27. <p>This is basically the only hard <em>rule</em> of the system. There is only one branch that has any specific and consistent meaning and we named it <code>master</code>. To us, this means that it has been deployed or at the worst will be deployed within hours. It’s incredibly rare that this gets rewound (the branch is moved back to an older commit to revert work) - if there is an issue, commits will be reverted or new commits will be introduced that fixes the issue, but the branch itself is almost never rolled back.</p>
  28. <p>The <code>master</code> branch is stable and it is always, always safe to deploy from it or create new branches off of it. If you push something to master that is not tested or breaks the build, you break the social contract of the development team and you normally feel pretty bad about it. Every branch we push has tests run on it and reported into the chat room, so if you haven’t run them locally, you can simply push to a topic branch (even a branch with a single commit) on the server and wait for <a href="http://jenkins-ci.org/">Jenkins</a> to tell you if it passes everything.</p>
  29. <p>You could have a <code>deployed</code> branch that is updated only when you deploy, but we don’t do that. We simply expose the currently deployed SHA through the webapp itself and <code>curl</code> it if we need a comparison made.</p>
  30. <h4>#2 - create descriptive branches off of master</h4>
  31. <p>When you want to start work on anything, you create a descriptively named branch off of the stable <code>master</code> branch. Some examples in the GitHub codebase right now would be <code>user-content-cache-key</code>, <code>submodules-init-task</code> or <code>redis2-transition</code>. This has several advantages - one is that when you fetch, you can see the topics that everyone else has been working on. Another is that if you abandon a branch for a while and go back to it later, it’s fairly easy to remember what it was.</p>
  32. <p>This is nice because when we go to the GitHub branch list page we can easily see what branches have been worked on recently and roughly how much work they have on them.</p>
  33. <p><img src="https://cloud.githubusercontent.com/assets/70/6769774/7988902c-d0a8-11e4-94c9-dc132461ffe4.png" alt="github branch list"/></p>
  34. <p>It’s almost like a list of upcoming features with current rough status. This page is awesome if you’re not using it - it only shows you branches that have unique work on them relative to your currently selected branch and it sorts them so that the ones most recently worked on are at the top. If I get really curious, I can click on the ‘Compare’ button to see what the actual unified diff and commit list is that is unique to that branch.</p>
  35. <p>So, as of this writing, we have 44 branches in our repository with unmerged work in them, but I can also see that only about 9 or 10 of them have been pushed to in the last week.</p>
  36. <h4>#3 - push to named branches constantly</h4>
  37. <p>Another big difference from git-flow is that we push to named branches on the server constantly. Since the only thing we really have to worry about is <code>master</code> from a deployment standpoint, pushing to the server doesn’t mess anyone up or confuse things - everything that is not <code>master</code> is simply something being worked on.</p>
  38. <p>It also make sure that our work is always backed up in case of laptop loss or hard drive failure. More importantly, it puts everyone in constant communication. A simple ‘git fetch’ will basically give you a TODO list of what every is currently working on.</p>
  39. <pre><code>$ git fetch
  40. remote: Counting objects: 3032, done.
  41. remote: Compressing objects: 100% (947/947), done.
  42. remote: Total 2672 (delta 1993), reused 2328 (delta 1689)
  43. Receiving objects: 100% (2672/2672), 16.45 MiB | 1.04 MiB/s, done.
  44. Resolving deltas: 100% (1993/1993), completed with 213 local objects.
  45. From github.com:github/github
  46. * [new branch] charlock-linguist -&gt; origin/charlock-linguist
  47. * [new branch] enterprise-non-config -&gt; origin/enterprise-non-config
  48. * [new branch] fi-signup -&gt; origin/fi-signup
  49. 2647a42..4d6d2c2 git-http-server -&gt; origin/git-http-server
  50. * [new branch] knyle-style-commits -&gt; origin/knyle-style-commits
  51. 157d2b0..d33e00d master -&gt; origin/master
  52. * [new branch] menu-behavior-act-i -&gt; origin/menu-behavior-act-i
  53. ea1c5e2..dfd315a no-inline-js-config -&gt; origin/no-inline-js-config
  54. * [new branch] svg-tests -&gt; origin/svg-tests
  55. 87bb870..9da23f3 view-modes -&gt; origin/view-modes
  56. * [new branch] wild-renaming -&gt; origin/wild-renaming
  57. </code></pre>
  58. <p>It also lets everyone see, by looking at the GitHub Branch List page, what everyone else is working on so they can inspect them and see if they want to help with something.</p>
  59. <h4>#4 - open a pull request at any time</h4>
  60. <p>GitHub has an amazing code review system called <a href="http://help.github.com/send-pull-requests/">Pull Requests</a> that I fear not enough people know about. Many people use it for open source work - fork a project, update the project, send a pull request to the maintainer. However, it can also easily be used as an internal code review system, which is what we do.</p>
  61. <p>Actually, we use it more as a branch conversation view more than a pull request. You can send pull requests from one branch to another in a single project (public or private) in GitHub, so you can use them to say “I need help or review on this” in addition to “Please merge this in”.</p>
  62. <p><img src="https://cloud.githubusercontent.com/assets/70/6769770/61a2dcba-d0a8-11e4-9924-3576232053ee.png" alt="early pr message"/></p>
  63. <p>Here you can see Josh cc'ing Brian for review and Brian coming in with some advice on one of the lines of code. Further down we can see Josh acknowledging Brian’s concerns and pushing more code to address them.</p>
  64. <p><img src="https://cloud.githubusercontent.com/assets/70/6769767/5054b4ba-d0a8-11e4-8d38-548ecf157018.png" alt="more discussion"/></p>
  65. <p>Finally you can see that we’re still in the trial phase - this is not a deployment ready branch yet, we use the Pull Requests to review the code long before we actually want to merge it into <code>master</code> for deployment.</p>
  66. <p>If you are stuck in the progress of your feature or branch and need help or advice, or if you are a developer and need a designer to review your work (or vice versa), or even if you have little or no code but some screenshot comps or general ideas, you open a pull request. You can cc people in the GitHub system by adding in a @username, so if you want the review or feedback of specific people, you simply cc them in the PR message (as you saw Josh do above).</p>
  67. <p>This is cool because the Pull Request feature let’s you comment on individual lines in the unified diff, on single commits or on the pull request itself and pulls everything inline to a single conversation view.
  68. It also let you continue to push to the branch, so if someone comments that you forgot to do something or there is a bug in the code, you can fix it and push to the branch, GitHub will show the new commits in the conversation view and you can keep iterating on a branch like that.</p>
  69. <p>If the branch has been open for too long and you feel it’s getting out of sync with the master branch, you can merge master into your topic branch and keep going. You can easily see in the pull request discussion or commit list when the branch was last brought up to date with the ‘master’.</p>
  70. <p><img src="https://cloud.githubusercontent.com/assets/70/6769754/2162f69e-d0a8-11e4-8c98-d2bb581f7152.png" alt="master merge"/></p>
  71. <p>When everything is really and truly done on the branch and you feel it’s ready to deploy, you can move on to the next step.</p>
  72. <h4>#5 - merge only after pull request review</h4>
  73. <p>We don’t simply do work directly on <code>master</code> or work on a topic branch and merge it in when we think it’s done - we try to get signoff from someone else in the company. This is generally a +1 or emoji or “:shipit:” comment, but we try to get someone else to look at it.</p>
  74. <p><img src="https://cloud.githubusercontent.com/assets/70/6769753/0ea37c4a-d0a8-11e4-8b61-7aa73b7e3b03.png" alt="shipit comment"/></p>
  75. <p>Once we get that, and the branch passes CI, we can merge it into master for deployment, which will automatically close the Pull Request when we push it.</p>
  76. <h4>#6 - deploy immediately after review</h4>
  77. <p>Finally, your work is done and merged into the <code>master</code> branch. This means that even if you don’t deploy it now, people will base new work off of it and the next deploy, which will likely happen in a few hours, will push it out. So since you really don’t want someone else to push something that you wrote that breaks things, people tend to make sure that it really is stable when it’s merged and people also tend to push their own changes.</p>
  78. <p>Our campfire bot, hubot, can do deployments for any of the employees, so a simple:</p>
  79. <pre><code>hubot depoy github to production
  80. </code></pre>
  81. <p>will deploy the code and zero-downtime restart all the necessary processes. You can see how common this is at GitHub:</p>
  82. <p><img src="https://cloud.githubusercontent.com/assets/70/6769750/ebc7b3da-d0a7-11e4-96e3-cfe0cea6ae51.png" alt="our campfire logs"/></p>
  83. <p>You can see 6 different people (including a support guy and a designer) deploying about 24 times in one day.</p>
  84. <p>I have done this for branches with one commit containing a one line change. The process is simple, straightforward, scalable and powerful. You can do it with feature branches with 50 commits on them that took 2 weeks, or 1 commit that took 10 minutes. It is such a simple and frictionless process that you are not annoyed that you have to do it even for 1 commit, which means people rarely try to skip or bypass the process unless the change is so small or insignificant that it just doesn’t matter.</p>
  85. <p>This is an incredibly simple and powerful process. I think most people would agree that GitHub has a very stable platform, that issues are addressed quickly if they ever come up at all, and that new features are introduced at a rapid pace. There is no compromise of quality or stability so that we can get more speed or simplicity or less process.</p>
  86. <h2>Conclusion</h2>
  87. <p>Git itself is fairly complex to understand, making the workflow that you use with it more complex than necessary is simply adding more mental overhead to everybody’s day. I would always advocate using the simplest possible system that will work for your team and doing so until it doesn’t work anymore and then adding complexity only as absolutely needed.</p>
  88. <p>For teams that have to do formal releases on a longer term interval (a few weeks to a few months between releases), and be able to do hot-fixes and maintenance branches and other things that arise from shipping so infrequently, <a href="http://nvie.com/posts/a-successful-git-branching-model/">git-flow</a> makes sense and I would highly advocate it’s use.</p>
  89. <p>For teams that have set up a culture of shipping, who push to production every day, who are constantly testing and deploying, I would advocate picking something simpler like GitHub Flow.</p>