<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matteo Codogno</title>
    <description>The latest articles on DEV Community by Matteo Codogno (@matteocodogno).</description>
    <link>https://dev.to/matteocodogno</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F383686%2F7d0751f6-0265-4b1f-a795-f50010268028.jpeg</url>
      <title>DEV Community: Matteo Codogno</title>
      <link>https://dev.to/matteocodogno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matteocodogno"/>
    <language>en</language>
    <item>
      <title>Go with the (git)flow, or die debating</title>
      <dc:creator>Matteo Codogno</dc:creator>
      <pubDate>Mon, 11 Sep 2023 08:12:23 +0000</pubDate>
      <link>https://dev.to/matteocodogno/go-with-the-gitflow-or-die-debating-ck0</link>
      <guid>https://dev.to/matteocodogno/go-with-the-gitflow-or-die-debating-ck0</guid>
      <description>&lt;p&gt;We all version our codebase using one of the many version control systems (VCS) on the market. Since I started working for &lt;a href="https://www.welld.ch/it/index.html?utm_source=Medium&amp;amp;utm_medium=ContentMarketing&amp;amp;utm_content=Gowiththegit"&gt;wellD&lt;/a&gt;, we have changed three of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the beginning, we were using &lt;em&gt;CVS&lt;/em&gt;&lt;/strong&gt;, but given its inability to be atomic–in an &lt;em&gt;all-or-nothing&lt;/em&gt; sense–it really wasn’t fun when something got stuck halfway through. Let’s not even mention its performances.&lt;br&gt;
 &lt;strong&gt;Our next step was then to switch to &lt;em&gt;SVN&lt;/em&gt;&lt;/strong&gt;; we &lt;strong&gt;chose not to go for &lt;em&gt;git&lt;/em&gt; because it was too &lt;em&gt;complex&lt;/em&gt;! As a result, merging two branches would always give us a headache.&lt;br&gt;
**Finally, it was &lt;em&gt;git&lt;/em&gt;-time&lt;/strong&gt;, which positively disrupted the way our developers’ team worked.&lt;/p&gt;

&lt;p&gt;Unlike the first two VCSs, however, &lt;em&gt;git&lt;/em&gt; forces users to define &lt;strong&gt;shared methodologies&lt;/strong&gt; to use the system.&lt;/p&gt;

&lt;p&gt;In this respect, one of the first challenges we faced was to agree on a shared &lt;strong&gt;branching strategy&lt;/strong&gt;. To make our decision, we considered the following criteria: easy-to-integrate &lt;strong&gt;Continuous Integration&lt;/strong&gt; (CI), &lt;strong&gt;frequent releases&lt;/strong&gt;, and step-by-step &lt;strong&gt;code review&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Branching strategy
&lt;/h2&gt;

&lt;p&gt;Keeping in mind the criteria we just mentioned, here is an &lt;strong&gt;overview of the branching strategies&lt;/strong&gt; we, directly and indirectly, experimented with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Anarchy strategy
&lt;/h3&gt;

&lt;p&gt;AKA “no-strategy.” This model empowers each developer to create branches *&lt;em&gt;without following any convention *&lt;/em&gt; whatsoever with respect to a branch’s duration, name, and content.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Ideally&lt;/em&gt;, this enables a quick kickoff and an independent development. But &lt;em&gt;alas&lt;/em&gt;, a much more tangible result is that it doesn’t take long for the situation to become &lt;strong&gt;impossible to manage&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By adopting this strategy, the team will have to spend time trying to identify the active development branch, on which branch they should develop code, on which branch(es) a specific feature is located, or which branch should be pushed to production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Git Flow
&lt;/h3&gt;

&lt;p&gt;For over a year, we used &lt;em&gt;git-flow&lt;/em&gt;, which provided us with an &lt;strong&gt;organized&lt;/strong&gt;, &lt;strong&gt;methodical&lt;/strong&gt;, and &lt;strong&gt;structured&lt;/strong&gt; alternative, and a CLI that allowed us to avoid naming convention issues.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Is7aMM9t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AaPXZJ1SUhjuB8KyCgueWQg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Is7aMM9t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AaPXZJ1SUhjuB8KyCgueWQg.png" alt="GitFlow CLI" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The idea behind &lt;em&gt;git-flow&lt;/em&gt; is pretty simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The master branch includes all the tags for all released versions;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The develop branch is used for ongoing development processes;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Feature branches are dedicated to the new features that are being developed;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Release branches are for software versions that are candidates for release;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hotfix branches are destined to bug fixes flagged by the production team.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Y2tdP3U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AXpAbI8DN8h25wKmanaTIYA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Y2tdP3U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AXpAbI8DN8h25wKmanaTIYA.png" alt="GitFlow schema" width="528" height="700"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The biggest problem with &lt;strong&gt;GitFlow&lt;/strong&gt; is its &lt;strong&gt;complexity&lt;/strong&gt;. The whole development process doesn’t occur on the master branch–i.e. the default branch for many tools–rather on develop, while master is only used to store releases.&lt;/p&gt;

&lt;p&gt;This kind of approach actually prevents developers from &lt;strong&gt;code reviewing&lt;/strong&gt; pending merge requests (MR) on the master branch–which are required since this branch is protected–as these will include content developed in weeks, if not months. It is, however, possible to send MRs from feature branches to the develop branch. Yet this only depends on the developer’s commitment, because MRs are not required for the develop branch since it is not protected, or at least it is not so by default.&lt;/p&gt;

&lt;p&gt;One of the greatest issues we had was &lt;strong&gt;to correct bugs in versions preceding the latest release&lt;/strong&gt;. Let’s say we released version &lt;code&gt;2.X&lt;/code&gt; of a software and the client flags us an issue in version &lt;code&gt;1.Z&lt;/code&gt;. The wisest choice would be to go on the master branch and create a support branch for tag &lt;code&gt;1.Z&lt;/code&gt; to fix the bug. But what should we do after the bug fix? From which branch should our fix be released: the &lt;code&gt;support&lt;/code&gt; branch, the &lt;code&gt;master&lt;/code&gt; branch, or something else? Into what should we merge our fix? Should it be merged in the &lt;code&gt;master&lt;/code&gt; branch or perhaps in the &lt;code&gt;develop&lt;/code&gt; branch? Or, rather, should we just leave the &lt;code&gt;support&lt;/code&gt; branch we created forever unmerged?&lt;/p&gt;

&lt;p&gt;The release process in GitFlow can get really tough. Here are the steps involved:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use the command &lt;code&gt;git flow release start &amp;lt;VERSION_NUMBER&amp;gt;&lt;/code&gt; to create the release branch from develop;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update your &lt;strong&gt;codebase&lt;/strong&gt; (&lt;strong&gt;changelog&lt;/strong&gt;, project version, readme, etc.;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait for the CI to green-light the creation of an MR on &lt;code&gt;master&lt;/code&gt;;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Merge the release branch into master with the command &lt;code&gt;git flow release finish &amp;lt;VERSION_NUMBER&amp;gt;&lt;/code&gt;. Once this step is done, the release branch will be merged into &lt;code&gt;master&lt;/code&gt; and &lt;code&gt;develop&lt;/code&gt;, and a &lt;code&gt;tag&lt;/code&gt; will be created for the release commit. After that, we will be redirected to &lt;code&gt;develop&lt;/code&gt;;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;push&lt;/strong&gt; &lt;code&gt;master&lt;/code&gt;, &lt;code&gt;develop&lt;/code&gt;, and the &lt;code&gt;tag&lt;/code&gt; (note: &lt;code&gt;git push --tags&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;P.S.: First, update the project version on develop for the next iteration, then &lt;strong&gt;push&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes this process can be overkill, and experience has taught me that making a mistake is quite easy.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Flow
&lt;/h3&gt;

&lt;p&gt;GitHub Flow relies on a &lt;strong&gt;clean&lt;/strong&gt; and &lt;strong&gt;simple&lt;/strong&gt; structure, with only 2 kinds of branches: the &lt;code&gt;master&lt;/code&gt; branch and the &lt;code&gt;feature&lt;/code&gt; branches. A developer creates a branch from the repository on which the new &lt;strong&gt;feature&lt;/strong&gt; is developed. Once done, an MR (with code review) is sent to master. To update an MR, you simply need to push content on your branch, and when the MR is ready this will be merged in master. After that, the feature branch is removed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--twCV7eJn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Agr9HebeZzALsZKQ8_Pt1qA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--twCV7eJn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Agr9HebeZzALsZKQ8_Pt1qA.png" alt="GitHub flow" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This branching strategy, however, is based on &lt;strong&gt;2 strong assumptions&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Developed contents can be pushed to production at any time, which is not always true. For many of our clients, we have a set time frame on a certain date to push a new software version to production.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clients always install the last version of our app, so there is no need to &lt;strong&gt;support&lt;/strong&gt; and &lt;strong&gt;fix bugs&lt;/strong&gt; for older releases. 🤔&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Gitlab Flow 🚀
&lt;/h3&gt;

&lt;p&gt;Starting from GitHub Flow, a new strategy came up, one that provides &lt;strong&gt;a branch for each environment&lt;/strong&gt;. Let’s say we have a &lt;strong&gt;staging&lt;/strong&gt; environment, a Quality Assurance (&lt;strong&gt;QA&lt;/strong&gt;) environment, and a &lt;strong&gt;Prod&lt;/strong&gt; environment. Each of them is updated automatically using a CI script pointing to the relevant branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--490XA-Jr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A1bWdU3Wv2Qoi-vQ-CFt2RA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--490XA-Jr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A1bWdU3Wv2Qoi-vQ-CFt2RA.png" alt="GitLab Flow environment branches" width="560" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like this, we can benefit from small and exact MRs to master, which can be subject to code review. When we’re ready, we can push changes to the QA environment (sending MRs from the master to the pre-production branch) and then to the Prod environment (sending MRs from the pre-production to the production branch).&lt;br&gt;
Thanks to this workflow, we can rest assured that all commits are tested in all environments.&lt;/p&gt;

&lt;p&gt;Sometimes, there is the need to keep developing multiple versions of a software, in which case &lt;strong&gt;Release Branches&lt;/strong&gt; come in handy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jsTjH_6B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AiZhT_0XqYv1aytooZ9nUjA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jsTjH_6B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AiZhT_0XqYv1aytooZ9nUjA.png" alt="GitLab Flow - Release branches" width="550" height="719"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, each branch corresponds to one version of our software (the image above depicts a &lt;em&gt;minor&lt;/em&gt; version.) In order to avoid making &lt;strong&gt;hotfixes&lt;/strong&gt; on multiple branches, the creation of the release branch (the &lt;em&gt;stable&lt;/em&gt; branch in the picture) is delayed for as long as possible.&lt;/p&gt;

&lt;p&gt;When an anomaly occurs in our software, the fix is made on a &lt;code&gt;feature&lt;/code&gt; branch, which is then merged into the &lt;code&gt;master&lt;/code&gt; branch. After that, we cherry-pick the commit on the release branch. This technique, known as &lt;strong&gt;Upstream First&lt;/strong&gt;, is used so that the developer doesn’t forget to merge a hotfix into master, preventing the problem from occurring in future releases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion 🤓
&lt;/h3&gt;

&lt;p&gt;One of the principles of &lt;strong&gt;&lt;a href="https://leankit.com/learn/lean/lean-methodology/"&gt;Lean&lt;/a&gt;&lt;/strong&gt; that I appreciate the most is continuous improvement, a concept that is perfectly depicted by this anecdote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There was once the owner of a big American company, who decided to adopt &lt;strong&gt;Lean&lt;/strong&gt; to improve his production line. A couple of months after introducing it, he invited the owner of a Japanese factory–where Lean had been implemented since day one–to visit his factory.&lt;br&gt;
 On the day of the meeting, the American gave his Japanese guest a tour of his factory, showing him the improvements that had been made thanks to Lean. The Japanese watched but didn’t make any comments.&lt;br&gt;
 At the end of the tour, the host asked his guest: “What do you think of the way we reorganized our factory by following your guidelines? Have we managed to embrace Lean fully?”&lt;br&gt;
 The Japanese guest answered: “I do not know that. I was not here yesterday!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is just to say that, starting from CVS, in time we have embraced &lt;strong&gt;git&lt;/strong&gt; and &lt;strong&gt;Gitlab Flow&lt;/strong&gt;, which currently seems to suit our development cycle well enough. Nonetheless, we are always open to experiment with and potentially adopt any tool or strategy that improves our developers’ team life.&lt;/p&gt;

&lt;h3&gt;
  
  
  References 🔗
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.gitlab.com/ee/workflow/gitlab_flow.html"&gt;https://docs.gitlab.com/ee/workflow/gitlab_flow.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://datasift.github.io/gitflow/IntroducingGitFlow.html"&gt;https://datasift.github.io/gitflow/IntroducingGitFlow.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://danielkummer.github.io/git-flow-cheatsheet/"&gt;https://danielkummer.github.io/git-flow-cheatsheet/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GitLab Flow example: &lt;a href="https://github.com/spring-projects/spring-boot"&gt;https://github.com/spring-projects/spring-boot&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Upstream first: &lt;a href="https://www.chromium.org/chromium-os/chromiumos-design-docs/upstream-first"&gt;https://www.chromium.org/chromium-os/chromiumos-design-docs/upstream-first&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;— &lt;br&gt;
&lt;a href="https://twitter.com/teo1690"&gt;Matteo Codogno&lt;/a&gt;, Technical Leader @&lt;a href="https://www.welld.ch/it/index.html?utm_source=Medium&amp;amp;utm_medium=ContentMarketing&amp;amp;utm_content=Gowiththegit"&gt;WellD&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>devops</category>
      <category>github</category>
    </item>
  </channel>
</rss>
