Overcome Merge Hell with Trunk based development and Continuous Integration

Posted on Oct 11, 2023

Overcome Merge Hell with Trunk based development and Continuous Integration

Overview

Different teams and projects require different workflows, as no one-size-fits-all approach exists. To enhance collaboration and tackle problems like merge hell, software teams have experimented with various techniques over the years.

Version control systems (VCS) revolutionized code management by introducing branches and merging capabilities. This paved the way for various branching and development strategies like Feature Branching and GitFlow. However, despite their benefits, these strategies often face the ongoing challenge known as Merge Hell.

The solution to this problem? Continuous Integration (CI), coupled with trunk-based development, provides a powerful approach to mitigate merge hell. CI ensures frequent integration of changes, while trunk-based development reduces complexity by emphasizing a single, stable main branch as the source of truth, enabling smoother collaboration and reducing the risk of integration issues.

So, in this blog, we will learn about the use and importance of CI and TBD with all its advantages and workflow.

What is Version Control?


Version control is a method or software that keeps track of changes made to files over time, enabling teams or developers to collaborate, track modifications, and easily revert to previous states. It organizes different versions of files and maintains a detailed record of adjustments, including contributors, timestamps, and specific changes made.

Here’s a scenario: Consider that you are editing a document over time. You might occasionally want to review an earlier document version or check to see if anyone else has made any modifications. Using version control is like having a time machine for your files.

Similarly, taking reference to the figure above, let’s consider our application, which has two versions: v0.1 and v0.2. In the event that any issues arise with v0.2, we always have the option to revert to the previous version.

Additionally, we can perform tasks such as comparing different versions, reverting to previous states, and merging changes from different versions. This flexibility allows us to manage our application effectively and address any problems that may arise while incorporating and integrating various updates.

Here, we will focus on git as our default version control.

Also Read: What are the Benefits of Amazon S3 Glacier?

Why branch in version control?


Branching in version control is a powerful feature that allows for parallel development and isolation of changes within a project. It makes it possible for numerous people or teams to work on various features, bug fixes, or experiments simultaneously without interfering with one another’s efforts.

Additionally, branching supports orderly and effective software development operations. Teams can set up branches for certain features, improvements, or bug fixes, enabling developers to work on several projects simultaneously. This concurrent development strategy boosts output and facilitates meeting project deadlines. In addition, branches offer a distinct separation of concerns, making it simpler to track changes, examine code, and, if required, roll back adjustments. Effective branching enables teams to maintain a disciplined and cooperative development process, facilitating easier change integration and reducing codebase conflicts.

Different Development Workflows: A Comparison

Over time, as Git and other version control systems developed to suit the demands of diverse development scenarios, new Git workflows were added.

Git workflows are several methods or techniques that teams can use to coordinate and manage projects while utilizing the Git version control system. Git workflows motivate DevOps teams and developers to use Git efficiently and consistently. Let’s investigate and evaluate a few typical Git workflows:

  1. Centralized Workflow:
    A central repository acts as the only reliable source of information in this workflow. The central repository is copied by developers, who then edit it and push the changes back.

  2. Feature Branch Workflow:
    This process focuses on creating separate branches for bug fixes or new features. Each new feature or problem receives its branch, which the developers work on before merging into the main branch.
    Due to The independence of each feature branch, it enables simultaneous development.

  3. GitFlow Workflow:
    Using the branching model known as GitFlow, development is divided into several branches for features, releases, and bug fixes. It makes use of branches such as “develop” for current work, “feature” for new features, “release” for preparing releases, and “hotfix” for urgent fixes.
    It works well for projects that need rigorous versioning and frequent releases.

  4. Forking Workflow:
    The forking method became more common as open-source development and remote team participation grew. Developers can fork a central repository to distinguish their copy from the original. Developers can freely modify their forks using this approach and then send pull requests to the main repository for review and merging.
    Forking encourages a decentralized development approach by enabling contributions from other collaborators while retaining control over the primary repository.

Challenges of Traditional Development Workflows


The traditional process, also known as the centralized workflow, faces a number of difficulties, one of which is referred to as “merge hell”, which we will discuss in the next section.

The centralized workflow allows for numerous developers to work together directly on a single branch, making changes as they go and committing them to the shared repository. Conflicts and challenges arise when integrating modifications from various team members as the number of developers and code changes grows. The resolution of these disputes might become difficult and drawn out.

Also Read: Unlock Cloud Migration with 8 Powerful AWS Migration Tools

Alternative workflows, like the Feature Branch Workflow or GitFlow, were introduced to address these issues. These processes encourage a more organized method of branching and let programmers focus just on one feature or task at a time. As a result, only fewer merge conflicts arise and modifications may be incorporated into the main branch more easily.

But even though alternative workflows aim to reduce merge conflicts and alleviate merge hell, it is still possible for merge conflicts to occur. Here are a few reasons why merge conflicts can still happen:

  1. Long-lived branches:
    If feature or development branches have long lifespans, they are more prone to accumulating conflicting changes over time. Conflicts are more likely to arise while attempting to merge a branch the longer it hasn’t been merged into the main branch.

  2. Parallel development:
    When several developers work on various features or tasks simultaneously, there is always a chance that some modifications will overlap and conflict when the code is merged. Even with well-organized workflows, this can still occur if engineers don’t consistently update their branches with the most recent modifications from the main branch.

  3. Lack of communication and coordination:
    Communication breakdowns or poor teamwork can cause conflicting modifications in several branches in collaborative contexts. Conflicts may occur when attempting to merge these branches if correct synchronization and alignment are not maintained.

  4. Major code refactor changes:
    When considerable code refactoring or reorganization occurs, it may result in extensive changes to numerous files and modules. When attempting to integrate the refactored code with existing branches, these changes may conflict with other ongoing development projects, resulting in merge conflicts. While refactoring aims to improve the code’s quality, readability, and maintainability, it can introduce conflicts when merging the refactored code with other branches. These conflicts arise when the changes made during refactoring overlap with modifications made in parallel by other developers or teams.

What is Merge Hell?

Merge hell refers to a situation where frequent and complex merge conflicts occur during the process of merging code changes from multiple branches. It frequently leads to time-consuming and clumsy attempts to resolve these issues.

Let us consider a scenario,

Imagine a software development project where Alice and Bob, two developers, are each working on a feature branch that is descended from the main branch. Bob is working on a feature that will create a notification system, while Alice is developing a feature that will provide user authentication capability.

  1. Alice and Bob starts working on their respective feature branches at once, making frequent changes to the codebase.

  2. After some time, Alice finishes her feature and successfully merges it into the main branch without any issues.

  3. Meanwhile, Bob continues working on his feature branch, making significant changes to various files, including some areas that Alice modified for the user authentication feature.

  4. When Bob finishes his feature and attempts to merge it into the main branch, conflicts arise due to the overlapping changes in the codebase. This is merge hell in action.

  5. Bob discovers that the changes Alice made to user authentication conflict with how he implemented the notification system. He has to alter his code to consider the new authentication feature, which adds more time to the dispute resolution process.

  6. As more conflicts arise during the merge process, Bob’s productivity decreases, and frustration builds up. Determining the root cause of conflicts and finding an optimal resolution becomes challenging.

This illustration shows how developers working on different branches with overlapping modifications might end up in merge hell. One of the ways to reduce such hassle is by implementing Continuous Integration along with Trunk-Based Development.

Intro to Continuous Integration and Trunk-Based Development

Continuous Integration (CI) is a development methodology in which programmers routinely integrate their code changes into a common repository. The primary goal of CI is to automatically integrate and validate code changes in order to identify and fix integration problems as soon as possible.

Here’s how continuous integration works:

  1. Code Repository:
    • Developers modify the source code while working on their local codebases.
  2. Automated Build:
    • A CI server or build system instantly gets the most recent code when developers commit their modifications to the repository.
  3. Automated Testing:
    • A series of automated tests are run after the code has been created. This covers integration tests, unit tests, and other project-specific test types.
  4. Integration and Validation:
    • The code is incorporated into a common branch or trunk after it passes the automated tests. To ensure that all modifications coexist without conflict, the CI server combines the changes with the current codebase.
  5. Notification and Feedback:
    • The build and test results receive quick feedback from the CI server. The build status, test results, and any potential integration problems are communicated to developers.

    Trunk-based development (TBD) is a modern software development approach that emphasizes keeping a single branch, called the “trunk” or “mainline” as the primary development branch.

    The idea is you work in master or close to master and you make small simple changes and get them integrated into the main as soon as possible. The goal of trunk-based development is to promote collaboration, streamline development, and enable faster feedback loops.

    One of the best things about TBD is that it enables code reviews and makes it much more easier and efficient. It is easier to review smaller chunks of code rather than hopelessly gazing at 1000 lines of code changes.


    Trunk-based development also allows for relatively short-lived branches because they are removed as soon as a developer pushes or submits their changes to the trunk.

    But why are short-lived branches a good thing?

    Think branching as an integration credit card. And just like any credit, you eventually have to pay off the debt at some point. The more the debt remains the more it gets difficult. With short-lived branches,  you don’t have to worry about debt accumulating in the form of merge conflicts.

    Let's see how Trunk Based Development works,


    In trunk-based development, the primary branches are the trunk (also known as the main branch or the master branch) and feature branches. The trunk represents the mainline development, while feature branches are created to work on specific features or changes.

    The developer occasionally updates the feature branch with the most recent modifications from the trunk when working with it. The modifications from the trunk into the feature branch are merged or integrated during this process. By doing this, the feature branch maintains sync with the most recent version of the trunk and incorporates any updates or problem fixes.

    The developer repeatedly works on the feature branch throughout the development process, adding and changing things as needed. The feature is prepared to be merged back into the trunk once it has been finished and tested.

    A final merge operation is carried out by the developer to combine the feature branch with the trunk. The new feature and the current codebase are combined in this process by incorporating the modifications made in the feature branch into the trunk. The completed feature is now a part of the mainstream development because it is now a part of the trunk.

    How TBD and CI mitigate the problem of Merge Hell

    In the above scenario of Bob and Alice, let's see how they can use TBD and CI to solve their problems.

    1. Create feature branches: Bob and Alice would create their own feature branches from the main/trunk branch to work on their respective features. For example, Alice could create a branch called “Auth Branch” and Bob could create a branch called “Notification Branch.”


    2. Develop features in their branches: Alice would work on implementing the authentication feature in her branch, while Bob would work on the notification system in his branch. They would make regular commits to their feature branches as they progress. Alice completes a part of the feature and merges the changes in the trunk in a short time. Once the feature gets successfully merged, the branch gets deleted.


    3. Bring Trunk up to date: In the meantime, Bob regularly examines any modifications made to the trunk, merges those modifications, and integrates them with his own codebase. After thorough testing, his changes are also merged into the trunk.


    4. Pull Requests: The pull request requests the original repository’s maintainers to review your changes and potentially merge them into the main codebase. Alice and Bob do not directly integrate their code into the main branch in the given situation. Instead, they submit a pull request, which serves as a request to merge their code changes into the primary branch. This pull request undergoes a review process where designated reviewers evaluate the code and decide whether or not to proceed with the merge. 
      During the review, the reviewers thoroughly examine the code, test its functionality, and assess its adherence to coding standards and best practices. They may also consider performance, scalability, security, and overall system compatibility factors.
      Reviewers play a crucial role in ensuring the quality and reliability of the codebase. They have the expertise to identify potential issues, bugs, or design flaws. If any such problems are found, the reviewers can provide valuable feedback and suggest changes that must be addressed before merging the code. These suggestions may include improvements, optimizations, or adjustments to make the code more efficient, maintainable, or compliant with the project’s guidelines.

    5. Continuous Integration: Continuous Integration (CI) is triggered every time Bob or Alice pushes their code changes, or a pull request is created, and it initiates automated build and testing processes. This streamlined approach significantly eases and accelerates the development cycle.
      CI springs into action whenever Bob or Alice pushes their code, executing automated tasks. Firstly, it initiates the automated build process, which involves compiling the code, resolving dependencies, and generating the necessary artifacts. Automating this process minimizes potential human errors, ensuring consistency in the build.
      Simultaneously, CI kicks off the automation testing phase. This encompasses a suite of tests that verify the functionality and quality of the code. It includes various tests, such as unit tests, integration tests, and other relevant tests specific to the project. The automated tests provide quick and accurate feedback on the correctness of the code changes.
      Several well-known CI/CD (Continuous Integration/Continuous Deployment) technologies offer automated build and test capabilities for CI implementation. These are commonly used CI tools: Jenkins, Travis CI, CircleCI, GitLab CI/CD, and GitHub Actions.
      Here is an example of CI workflow with automated testing. Every time code is pushed into the trunk, a series of tests runs to ensure the correctness and quality of code.


    Conclusion

    In conclusion, the combination of continuous integration (CI) and trunk-based development offers significant advantages for the development process. CI detects conflicts and compatibility issues early, preventing them from accumulating and reducing the likelihood of merge conflicts later on. Trunk-based development promotes collaboration, streamlines development efforts, and minimizes the risk of conflicts through iterative and focused changes.

    Read also: Top 10 AWS DevOps Tools to Pick for Your Business

    Together, CI and trunk-based development create an efficient and harmonious environment, ensuring an up-to-date and stable codebase, smoother code integration, and faster development cycles. By adopting these practices, teams can deliver high-quality software more effectively and with reduced merge conflicts.

    Overcome Merge Hell with Trunk based development and Continuous Integration
    Rohan Jha

    Latest Blogs

    New AWS Announcement for October 2023

    New AWS Announcement for October 2023


    New AWS Announcement for October 2023

    Adex International

    Nov 08, 2023

    Sustainability in the AWS Well-Architected Framework: A Comprehensive Guide

    Sustainability in the AWS Well-Architected Framework: A Comprehensive Guide


    Sustainability in the AWS Well-Architected Framework: A Comprehensive Guide

    Adex International

    Oct 19, 2023

    AWS New Announcement Sept 2023

    AWS New Announcement Sept 2023


    AWS New Announcement Sept 2023

    Adex International

    Oct 17, 2023

    Migrate Gitlab PostgreSQL Database to Custom Location Using Ansible

    Migrate Gitlab PostgreSQL Database to Custom Location Using Ansible


    Migrate Gitlab PostgreSQL Database to Custom Location Using Ansible

    Saugat Tiwari

    Oct 11, 2023

    Mastering DevOps: Your Ultimate Guide to DevOps Managed Services

    Mastering DevOps: Your Ultimate Guide to DevOps Managed Services


    Mastering DevOps: Your Ultimate Guide to DevOps Managed Services

    Biswash Giri

    Oct 11, 2023

    Discover the Benefits of Security as a Service (SECaaS) for your Business

    Discover the Benefits of Security as a Service (SECaaS) for your Business


    Discover the Benefits of Security as a Service (SECaaS) for your Business

    Saugat Tiwari

    Oct 11, 2023

    Port Forwarding Using AWS System Manager Session Manager

    Port Forwarding Using AWS System Manager Session Manager


    Port Forwarding Using AWS System Manager Session Manager

    Saugat Tiwari

    Oct 11, 2023

    Maximizing Directory Services with LDAP: Creating OUs, Groups, and Users for Improved Authentication and Access Control

    Maximizing Directory Services with LDAP: Creating OUs, Groups, and Users for Improved Authentication and Access Control


    Maximizing Directory Services with LDAP: Creating OUs, Groups, and Users for Improved Authentication and Access Control

    Biswash Giri

    Oct 11, 2023

    AWS Migration Tools: A Comprehensive Guide

    AWS Migration Tools: A Comprehensive Guide

    IntroductionAWS migration tools are a comprehensive set of services and utilities provided by Amazon...


    AWS Migration Tools: A Comprehensive Guide

    Binaya Puri

    Oct 11, 2023

    Difference Between AWS Cloudwatch and Cloudtrail

    Difference Between AWS Cloudwatch and Cloudtrail

    AWS CloudWatch and AWS CloudTrails are sometimes difficult to distinguish. This article seeks to d...


    Difference Between AWS Cloudwatch and Cloudtrail

    Sabin Joshi

    Oct 11, 2023

    New AWS Announcements for June 2023 - Adex

    New AWS Announcements for June 2023 - Adex


    New AWS Announcements for June 2023 - Adex

    Ravi Gupta

    Oct 11, 2023

    Top 7 Applications Of Cloud Computing In Various Field

    Top 7 Applications Of Cloud Computing In Various Field


    Top 7 Applications Of Cloud Computing In Various Field

    Susmita Karki Chhetri

    Oct 11, 2023

    Ingesting and Monitoring Custom Metrics in CloudWatch With AWS Lambda

    Ingesting and Monitoring Custom Metrics in CloudWatch With AWS Lambda


    Ingesting and Monitoring Custom Metrics in CloudWatch With AWS Lambda

    Tej pandey

    Oct 11, 2023

    7 Types of Security in Cloud Computing?

    7 Types of Security in Cloud Computing?


    7 Types of Security in Cloud Computing?

    Mukesh Awasthi

    Oct 11, 2023

    Cost-effective Use cases & Benefits of Amazon S3

    Cost-effective Use cases & Benefits of Amazon S3


    Cost-effective Use cases & Benefits of Amazon S3

    Nischal Gautam

    Oct 11, 2023

    IT Outsourcing: Everything You Need To Know

    IT Outsourcing: Everything You Need To Know

    The world has changed, and as technology advances, so does the world of work. Gone are the day...


    IT Outsourcing: Everything You Need To Know

    Roshan Raman Giri

    Oct 11, 2023

    Getting Started with Amazon Redshift in 6 Simple Steps

    Getting Started with Amazon Redshift in 6 Simple Steps


    Getting Started with Amazon Redshift in 6 Simple Steps

    Tej pandey

    Oct 11, 2023

    How to Host Static Websites on AWS S3?

    How to Host Static Websites on AWS S3?

    How to Host Static Websites on AWS S3? Hosting a Static Website on AWS S3 has a lot of benefits....


    How to Host Static Websites on AWS S3?

    Ravi Gupta

    Oct 11, 2023

    The Importance of Managed Cloud Security for Businesses

    The Importance of Managed Cloud Security for Businesses


    The Importance of Managed Cloud Security for Businesses

    Roshan Raman Giri

    Oct 11, 2023

    How To Use Amazon S3 For Personal Backup?

    How To Use Amazon S3 For Personal Backup?


    How To Use Amazon S3 For Personal Backup?

    Tej pandey

    Oct 11, 2023

    Major AWS Updates &Announcements of 2023 - March

    Major AWS Updates &Announcements of 2023 - March


    Major AWS Updates &Announcements of 2023 - March

    Roshan Raman Giri

    Oct 11, 2023

    How To Insert Data Into a DynamoDB Table with Boto3

    How To Insert Data Into a DynamoDB Table with Boto3

    DynamoDB is used for many use cases, including web and mobile applications, gaming, ad tech,...


    How To Insert Data Into a DynamoDB Table with Boto3

    Binaya Puri

    Oct 11, 2023

    How to Install and Upgrade the AWS CDK CLI

    How to Install and Upgrade the AWS CDK CLI


    How to Install and Upgrade the AWS CDK CLI

    Nischal Gautam

    Oct 11, 2023

    Ultimate Guide on Creating Terraform Modules

    Ultimate Guide on Creating Terraform Modules


    Ultimate Guide on Creating Terraform Modules

    Tej pandey

    Oct 11, 2023

    What is serverless computing?

    What is serverless computing?


    What is serverless computing?

    Tej pandey

    Oct 11, 2023

    AWS Well-Architected Framework Security Pillar

    AWS Well-Architected Framework Security Pillar

    The Amazon Well-Architected Framework is a set of recommendations and practice guidelines for develo...


    AWS Well-Architected Framework Security Pillar

    Binaya Puri

    Oct 11, 2023

    Amazon FSx for Lustre, Windows, and NetApp ONTAP

    Amazon FSx for Lustre, Windows, and NetApp ONTAP

    Amazon FSx for Lustre, Windows, and NetApp ONTAPAmazon FSx is known for its fully managed, hig...


    Amazon FSx for Lustre, Windows, and NetApp ONTAP

    Ravi Gupta

    Oct 11, 2023

    How to Choose the Right Cloud Service Provider?

    How to Choose the Right Cloud Service Provider?


    How to Choose the Right Cloud Service Provider?

    Tej pandey

    Oct 11, 2023

    25 New AWS Services Updates from AWS Re:Invent 2022

    25 New AWS Services Updates from AWS Re:Invent 2022


    25 New AWS Services Updates from AWS Re:Invent 2022

    Susmita Karki Chhetri

    Oct 11, 2023

    AWS Managed Hosting Services And Dedicated Hosting Benefits

    AWS Managed Hosting Services And Dedicated Hosting Benefits


    AWS Managed Hosting Services And Dedicated Hosting Benefits

    Tej pandey

    Oct 11, 2023

    What is Serverless Security? Risk & Best Practices

    What is Serverless Security? Risk & Best Practices

    Serverless computing  is a rising topic right now in the cloud tech industry. As per a Datad...


    What is Serverless Security? Risk & Best Practices

    Anup Giri

    Oct 11, 2023

    Difference Between Cloud Computing and Cybersecurity

    Difference Between Cloud Computing and Cybersecurity


    Difference Between Cloud Computing and Cybersecurity

    Mukesh Awasthi

    Oct 11, 2023

    DevOps for Developers: How It Helps Streamline the Development Process

    DevOps for Developers: How It Helps Streamline the Development Process

    As per a survey done by Puppet, firms with DevOps practice have increased recovery speeds by 24 ti...


    DevOps for Developers: How It Helps Streamline the Development Process

    Roshan Raman Giri

    Oct 11, 2023

    New AWS Announcements for August 2023

    New AWS Announcements for August 2023


    New AWS Announcements for August 2023

    Rohan Jha

    Oct 11, 2023

    The FinOps Chronicles

    The FinOps Chronicles


    The FinOps Chronicles

    Anup Giri

    Oct 11, 2023

    AWS Auto scale Instance-Based on RabbitMQ Custom Metrics

    AWS Auto scale Instance-Based on RabbitMQ Custom Metrics


    AWS Auto scale Instance-Based on RabbitMQ Custom Metrics

    Anup Giri

    Oct 11, 2023

    Overcome Merge Hell with Trunk based development and Continuous Integration

    Overcome Merge Hell with Trunk based development and Continuous Integration


    Overcome Merge Hell with Trunk based development and Continuous Integration

    Rohan Jha

    Oct 11, 2023

    What's the difference between CapEX Vs OpEX in Cloud Computing?

    What's the difference between CapEX Vs OpEX in Cloud Computing?


    What's the difference between CapEX Vs OpEX in Cloud Computing?

    Tej pandey

    Oct 11, 2023

    How Does Your Organization Keep Cloud Costs Under Control?

    How Does Your Organization Keep Cloud Costs Under Control?


    How Does Your Organization Keep Cloud Costs Under Control?

    Susmita Karki Chhetri

    Oct 11, 2023

    Microsoft Azure vs AWS vs Google Cloud Comparison

    Microsoft Azure vs AWS vs Google Cloud Comparison


    Microsoft Azure vs AWS vs Google Cloud Comparison

    Mukesh Awasthi

    Oct 11, 2023

    What are the Benefits of Amazon S3 Glacier?

    What are the Benefits of Amazon S3 Glacier?


    What are the Benefits of Amazon S3 Glacier?

    Anup Giri

    Oct 11, 2023

    Leverage Azure Migrate to Discover and Assess Your AWS Instances for Smooth Migration to Azure

    Leverage Azure Migrate to Discover and Assess Your AWS Instances for Smooth Migration to Azure


    Leverage Azure Migrate to Discover and Assess Your AWS Instances for Smooth Migration to Azure

    Rohan Jha

    Oct 11, 2023