<?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: John Breen</title>
    <description>The latest articles on DEV Community by John Breen (@jvbreen1).</description>
    <link>https://dev.to/jvbreen1</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%2F135342%2F67f183e8-a0a0-46c1-a31b-5a091f2180a3.jpeg</url>
      <title>DEV Community: John Breen</title>
      <link>https://dev.to/jvbreen1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jvbreen1"/>
    <language>en</language>
    <item>
      <title>All About that Rebase</title>
      <dc:creator>John Breen</dc:creator>
      <pubDate>Thu, 23 Jan 2020 03:39:05 +0000</pubDate>
      <link>https://dev.to/jvbreen1/all-about-that-rebase-226c</link>
      <guid>https://dev.to/jvbreen1/all-about-that-rebase-226c</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I originally posted this on &lt;a href="https://breen.tech/post/git-merge-patterns/"&gt;My Blog&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Take 3 commits: &lt;strong&gt;abc&lt;/strong&gt;, &lt;strong&gt;def&lt;/strong&gt;, &lt;strong&gt;ghi&lt;/strong&gt;&lt;br&gt;
And let's suppose you have two git branches: &lt;strong&gt;master&lt;/strong&gt; and &lt;strong&gt;production&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Production's history currently looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;abc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Master is two commits ahead:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;abc -&amp;gt; def -&amp;gt; ghi&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You open a Pull Request to get &lt;strong&gt;def&lt;/strong&gt; and &lt;strong&gt;ghi&lt;/strong&gt; into &lt;strong&gt;production&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge types
&lt;/h2&gt;

&lt;p&gt;You have a few options for how to merge the Pull Request. All of these methods serve the purpose of getting the code from &lt;strong&gt;def&lt;/strong&gt; and &lt;strong&gt;ghi&lt;/strong&gt; into the &lt;strong&gt;production&lt;/strong&gt; branch - the main differences center around the commit histories of the two branches afterwards.&lt;/p&gt;

&lt;h3&gt;
  
  
  Merge Commit
&lt;/h3&gt;

&lt;p&gt;I very rarely use this option in my work. As I understand it, it creates a sepearate commit, let's call it &lt;strong&gt;jkl&lt;/strong&gt;, that describes the merging of &lt;strong&gt;ghi&lt;/strong&gt; into &lt;strong&gt;production&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Squash Merge
&lt;/h3&gt;

&lt;p&gt;Squash merge combines &lt;strong&gt;def&lt;/strong&gt; and &lt;strong&gt;ghi&lt;/strong&gt; into a new commit, let's call it &lt;strong&gt;mno&lt;/strong&gt;, and then merges that.&lt;/p&gt;

&lt;p&gt;If you squash merge your PR, you'd end up with:&lt;/p&gt;

&lt;p&gt;master:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;abc -&amp;gt; def -&amp;gt; ghi&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;production:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;abc -&amp;gt; mno&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The commit histories for &lt;strong&gt;master&lt;/strong&gt; and &lt;strong&gt;production&lt;/strong&gt;, even though they have the same code, no longer have the same commits in them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rebase Merge
&lt;/h3&gt;

&lt;p&gt;Rebase merge replays all of the new commits (&lt;strong&gt;def&lt;/strong&gt; and &lt;strong&gt;ghi&lt;/strong&gt;) onto production:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abc
abc -&amp;gt; def
abc -&amp;gt; def -&amp;gt; ghi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;At the end, &lt;strong&gt;master&lt;/strong&gt; and &lt;strong&gt;production&lt;/strong&gt; would look exactly the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If I can help it, I prefer &lt;strong&gt;Rebase merge&lt;/strong&gt;. It avoids creating new commits, so it often results in a cleaner commit history between branches. Sometimes I use squash merge if my branch has a bunch of commits like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ahioh: feat: do something
inkcl: lint error
apsdq: fix test
apsap: please work
pwowq: Finally working
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That way, the commit history doesn't show my stream of consciousness as I fight with linters, continuous integration, and test suites.&lt;/p&gt;

&lt;p&gt;As I mentioned, I don't often use merge commits - I'm sure they have a use case, but I don't find them helpful to me a majority of the time.&lt;/p&gt;

</description>
      <category>git</category>
      <category>tools</category>
      <category>rebase</category>
      <category>merge</category>
    </item>
  </channel>
</rss>
