The typical developer workflow involves creating a pull request (PR)
, which must pass continuous integration (CI)
checks. Once these checks are passed and the PR is approved
, you get the option to merge the pull request.
You might think this means you can merge
the PR into the main branch without any issues, and the app will be deployed to production immediately. However, this isn’t always the case.
Imagine you are working in a large team that ships code to production rapidly. While you wait for your CI checks
to pass, many other developers are also waiting for their CI checks
to complete.
After you merge your PR, other developers will merge their PRs into the main branch as well. Each of these PRs passes CI checks
individually on their respective branches. However, there is no guarantee they will pass CI when combined in the main branch.
Things can go wrong, and conflicts are a common issue, especially soft conflicts, which are harder to detect. Soft conflicts are changes that pass CI independently but fail when combined with changes.
Common Issues While Merging PRs
Improper Rebase
: The PR might not have been rebased correctly. For example, it could have been rebased from last week’s main branch instead of the current one.Soft Conflicts
: Even if changes pass CI individually, they might fail when combined due to underlying conflicts.
Understanding and addressing these potential issues can help maintain the integrity of the main branch and ensure smooth deployments to production.
Pull Request Merge Queues Explained
To address these challenges, Pull Request Merge Queues
have been introduced, offering a transformative solution.
How Merge Queues Work
Merge queues simplify the way developers combine code changes by creating a special temporary branch. This temporary branch includes the following:
Target Branch's Source
: This is the main code that everyone is adding their changes to.Changes from Prior Pull Requests
: These are the updates from other developers that are waiting to be added before yours in the queue.Your Changes
: This includes the updates you want to merge into the main code.
All the changes—including yours—need to pass these checks successfully. If everything is okay, then the pull request can be merged into the main branch. This way, developers don’t have to run multiple checks separately for each update, making the whole process faster and more efficient.
From the official Github docs: The merge queue provides the same benefits as the Require branches to be up to date before merging branch protection, but does not require a pull request author to update their pull request branch and wait for status checks to finish before trying to merge.