<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marcus Larson on Medium]]></title>
        <description><![CDATA[Stories by Marcus Larson on Medium]]></description>
        <link>https://medium.com/@marcuslarson?source=rss-ae08104da16e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HTeG473NXD19iyLF</url>
            <title>Stories by Marcus Larson on Medium</title>
            <link>https://medium.com/@marcuslarson?source=rss-ae08104da16e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:08:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcuslarson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why You Should Never Squash Commits]]></title>
            <link>https://medium.com/@marcuslarson/why-you-should-never-squash-commits-69909429b278?source=rss-ae08104da16e------2</link>
            <guid isPermaLink="false">https://medium.com/p/69909429b278</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[git-squash]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-merge-vs-rebase]]></category>
            <dc:creator><![CDATA[Marcus Larson]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 13:06:38 GMT</pubDate>
            <atom:updated>2025-02-01T13:09:01.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rx8X4DbORvNvKgoahnRTKQ.png" /><figcaption>The Git history is the story of your code’s creation. Why erase its essence?</figcaption></figure><h3>Squshing commits is not the way to keep history clean</h3><p>In the world of Git, there’s an ongoing debate about whether to squash commits before merging a branch. Squashing compresses multiple commits into one, seemingly offering a cleaner history. But is this really the best approach? I’m on <a href="https://betterprogramming.pub/why-i-prefer-regular-merge-commits-over-squash-commits-cadd22cff02c">Derek Austin’s side preferring to not squash commits</a>. Instead, you should preserve all commits while using techniques like rebasing and rewriting history to maintain a clean and understandable commit log.</p><p><a href="https://betterprogramming.pub/why-i-prefer-regular-merge-commits-over-squash-commits-cadd22cff02c">Why I Prefer Regular Merge Commits Over Squash Commits</a></p><h4>The Problem with Squashing Commits</h4><p>At first glance, squashing commits might seem like a good idea. It reduces the number of commits, making the history in main branch appear less cluttered. However, this approach comes with significant downsides:</p><p>1. <strong>Loss of Context</strong>: Each commit in a branch represents a logical unit of work. When you squash commits, you lose the granularity and context that those individual commits provide. This can make it difficult to understand why certain changes were made, especially when revisiting the code months later.</p><p>2. <strong>Reduced Traceability</strong>: Squashing makes it harder to trace the evolution of a feature or bug fix. If you need to understand the reasoning behind a specific change or find the commit that introduced a bug, a squashed commit log will be of little help.</p><p>3. <strong>Poor Conflict Resolution</strong>: As mentioned in earlier articles, good commits help in resolving merge conflicts by providing a clear narrative of changes. Squashing removes this clarity, making conflict resolution more challenging and time-consuming.</p><p><a href="https://medium.com/@marcuslarson/how-to-avoid-those-nasty-merge-conflicts-392e51673fd2">How to Avoid Those Nasty Merge Conflicts</a></p><h3>The Case for Preserving Commits</h3><p>Preserving all commits allows you to maintain a detailed, informative history that serves multiple purposes:</p><p>1. <strong>Detailed Documentation</strong>: Each commit message acts as a piece of documentation, explaining the “what” and “why” of changes. This is invaluable when onboarding new team members or revisiting old code.</p><p>2. <strong>Easier Debugging</strong>: When bugs are introduced, the granular history provided by individual commits makes it easier to perform a `git bisect` and pinpoint the exact commit that caused the issue. This can save you significant time during debugging.</p><p>3. <strong>Better Collaboration</strong>: A detailed commit history helps your teammates understand the evolution of the codebase. It fosters better collaboration, as each developer can see not just what was done, but the reasoning behind it.</p><h3>Rebasing: The Key to a Clean History</h3><p>Instead of squashing commits, you should consider <strong>rebasing your branch before merging</strong>. Rebasing allows you to:</p><p>1. <strong>Rewrite History</strong>: With interactive rebasing, you can rewrite commit messages, reorder commits, and even combine them in a more meaningful way without losing essential information. This keeps the history clean and logical without sacrificing context. Keep doing this in your own development branch to always have a logical flow of commits that will eventually enter the main branch.</p><p>2. <strong>Rebase before Merge</strong>: Rebasing applies your changes on top of the current main branch, resulting in a linear history. This avoids the clutter of commits mixed from different branches, making the history easier to follow.</p><p><a href="https://medium.com/@flaviocopes/git-rebase-vs-merge-f969bd0866a4">Git, rebase vs merge</a></p><p>3. <strong>Resolve Conflicts Early</strong>: During a rebase, you can resolve conflicts incrementally, commit by commit, rather than dealing with them all at once during a merge. This makes conflict resolution more manageable and less error-prone with the prerequisite that you keep commits focused and related to the commit message.</p><p><a href="https://medium.com/@marcuslarson/how-to-avoid-those-nasty-merge-conflicts-392e51673fd2">How to Avoid Those Nasty Merge Conflicts</a></p><h3>Steps to Rebase and Clean Up Your Branch</h3><p>Here’s how to keep your history clean without squashing:</p><p>1. <strong>Interactive Rebase</strong>: Use `git rebase -i` to interactively rebase your branch. This lets you review each commit, edit commit messages, reorder commits, and fixup previous commits to make a logical clean history in your own branch.</p><p>2. <strong>Rewrite Commit Messages</strong>: Take the time to write clear, descriptive commit messages that explain the reasoning behind each change. This will make your history more valuable.</p><p>3. <strong>Test After Each Rebase</strong>: After rebasing, thoroughly test your branch to ensure that no issues have been introduced during the process.</p><p>4. <strong>Push with Force</strong>: Once you’ve cleaned up your branch, push the changes with `git push — force-with-lease`. This replaces the branch on the remote repository with your rebased branch.</p><h3>Conclusion</h3><p>While squashing commits may seem like a shortcut to a cleaner history, it often sacrifices the valuable context and traceability that makes Git such a powerful tool. By preserving all commits and using techniques like rebasing, fixup and force push to clean up your branch, you maintain a detailed, informative history that benefits both you and your team. The next time you’re preparing to merge a branch, resist the temptation to squash — your future self will thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69909429b278" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Avoid Those Nasty Merge Conflicts]]></title>
            <link>https://medium.com/@marcuslarson/how-to-avoid-those-nasty-merge-conflicts-392e51673fd2?source=rss-ae08104da16e------2</link>
            <guid isPermaLink="false">https://medium.com/p/392e51673fd2</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[merge-conflicts]]></category>
            <dc:creator><![CDATA[Marcus Larson]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 17:11:20 GMT</pubDate>
            <atom:updated>2025-01-09T17:46:52.033Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apAC7FRgX5c9T_LdvBBKZA.png" /><figcaption>Some tools make merge conflicts look like two worlds colliding, when in reality there is a very simple fix</figcaption></figure><p>Remember that time when you worked on a feature for a while, crafting the logic, fixing bugs, tweaking the user interface. You were productive, got all the tests passing, and said in the stand-up that code is all done now, just need to to click that merge button.</p><p>You confidently open up your pull request, and then… BAM! “Your branch has a merge conflict and cannot be merged”. Git can’t merge your branch without your help, and you’re left staring at a mountain of merge conflicts. What was supposed to take five minutes now turns into a frustrating, all-day affair of picking through code, deciphering what changed where, and praying you don’t accidentally delete something important.</p><p>We’ve all been there — spending an entire day resolving merge conflicts that seem to come out of nowhere. It feels like an inevitable part of being a developer, right?</p><p>Actually, it’s not. Those nasty, time-consuming merge conflicts often arise because of <strong>our own bad commit practices</strong>. But the good news is that by following a structured approach to committing changes, we can dramatically reduce the complexity of merge conflicts. In fact, with the right commit structure, resolving conflicts can be a quick and painless process.</p><p>Let’s dive into how to make that a reality.</p><h3>Why Bad Git Practices Cause Nasty Merge Conflicts</h3><p>Merge conflicts don’t just happen out of thin air — they’re a result of you changing the same lines of code as someone else, but they merged before you and now Git is unable to automatically reconcile changes between your branch and the target branch. The more messy, unrelated, and unstructured your commits are, the harder it is for both Git and you to figure out what to do when conflicts arise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amrd-jVlaGM6vGNzntnQgg.png" /></figure><p>If your commits are small, focused, and clearly documented, resolving conflicts becomes a much simpler task. Instead of untangling a mess, you’re making clear decisions based on what each commit was supposed to do.</p><h3>A Good Commit Standard to Avoid Nasty Merge Conflicts</h3><p>Here’s a guide to avoiding these big, nasty merge conflicts with a structured commit standard that will save you time and sanity.</p><p><strong>Make Separate Formatting Commits</strong></p><p>One of the biggest culprits for difficult merge conflicts is automatic formatting. Many developers use format plugins that automatically tidy up code whenever they save a file. While this is great for keeping your code consistent, it can wreak havoc when it comes to merging.</p><p>If you’re formatting files while also making other changes, Git can’t easily figure out which changes were intentional code edits and which were just formatting. This leads to confusing conflicts where formatting changes and actual code changes are all mixed together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*G60UkWBL-1UZsh_C5ehJlQ.png" /></figure><p>Create a separate commit for formatting changes. Before you start working on a file, format it first, and then commit that formatting as a standalone commit. That way, if a merge conflict arises later on, it’s easy to resolve. You’ll know that the conflict is just formatting and can quickly choose the target branch’s state, reformat the file, and move on. A conflict like this can be resolved in seconds.</p><p><strong>Keep Commits Focused and Related to the Commit Message</strong></p><p>Another common issue is unrelated changes being included in the same commit. Maybe you’re fixing a bug but also tweaking some styles or refactoring code. It’s tempting to just shove everything into one commit and move on, but this can lead to messy conflicts later.</p><p>When a conflict happens, Git will tell you there’s a problem between the changes in the current commit and the target branch. If your commit only includes changes related to one task, it’s much easier to resolve the conflict. You know exactly what the commit was meant to do, and you can focus on resolving the conflict with that context in mind.</p><p>If your commits are unfocused, with unrelated changes all mixed together, you’ll have to sort through each conflict and figure out which parts of the code should stay and which should go. This not only takes longer but also increases the risk of making mistakes and introducing bugs.</p><p>Only include changes in a commit that directly relate to the commit message. Break up unrelated changes into their own commits. This will make conflict resolution much easier and faster, as each commit will be clean, focused, and easy to understand.</p><p><a href="https://betterprogramming.pub/an-advice-for-developers-great-git-commit-messages-are-not-shorter-than-50-characters-2becf8fd481a">Advice for Developers: “Great Git Commit Messages Are Not Shorter Than 50 Characters”</a></p><p><strong>Solve conflicts by rebasing</strong></p><p>When you rebase your feature branch on top of the target branch, you step through each of your commits and apply them one by one on top of the latest code. This allows you to handle conflicts at the commit level, rather than trying to resolve everything at once. If a conflict happens during a rebase, it’s limited to a specific commit, making it easier to manage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvtysfNFoJljtxzwpoICVQ.png" /></figure><p>If your commits are well-structured, each conflict will be small, focused, and easy to resolve. You’ll know exactly what each commit was meant to do, and resolving the conflict will be straightforward.</p><h3>Conclusion</h3><p>Merge conflicts don’t have to be a nightmare. Most of the time, those big, frustrating conflicts are a result of poor Git practices — messy, unfocused commits, or combining formatting changes together with code changes. By adopting a structured commit standard, you can avoid these issues altogether.</p><p>Keep your commits small, focused, and related to the task at hand and separate your formatting changes into their own commits. With these practices in place, you’ll stop dreading merge conflicts altogether.</p><p>By taking control of your commit history, you’re not just preventing conflicts — you’re creating a development process that’s smoother, faster, and far less frustrating for both you and your reviewer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=392e51673fd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>