Stop Reverting your Commits, Use a Merge Queue: A Guide for Modern Developers

Stop Reverting your Commits, Use a Merge Queue: A Guide for Modern Developers

In this article, we explored the importance of stopping the habit of reverting commits and embracing the use of a merge queue in your CI/CD pipeline to secure the merging process.

Mathieu Poissard

Welcome, fellow code wranglers, to the Wild West of software development, where code conflicts are as common as tumbleweeds, and the git revert command is the town's overworked sheriff. If you've ever found yourself in a git mess, feeling like a cowboy trying to lasso a runaway commit, this article is for you. We will saddle up, ride into the sunset, and learn how to use a merge queue to keep our codebase cleaner than a whistle in a dust storm. So buckle up, partner, and turn those code conflicts into code con-friends.

The Usual Suspects: Causes Leading to Revert Commits

Before we dive into the magic of merge queues, let's take a gander at the usual suspects causing us to reach for that git revert command:

  1. The Lone Ranger: When developers work in isolation and merge their code at the last minute, it's like trying to fit a square peg in a round hole. Conflicts are bound to happen.
  2. The Quick Draw: Pushing code quickly without proper testing is like playing Russian roulette with your codebase. Sooner or later, you're going to hit a snag.
  3. The Tumbleweed: Code blowing around in the wind, not getting updated or tested against the latest changes, is asking for trouble.

The Good Practice: Running CI Before Merging Your Pull Request

Now that we've identified the outlaws let's talk about the sheriff that will keep them in check: Continuous Integration (CI). Running your CI before merging a pull request is like having a trusty deputy who checks for trouble before it starts. Here's how to deputize your CI:

  1. Configure Your CI/CD Pipeline: Set up your CI/CD pipeline to run automated tests and checks on every pull request.
  2. Make CI Status Visible: Ensure that the status of your CI checks is visible and easy to understand so developers can quickly see if there's trouble afoot.
  3. Enforce CI Checks: Configure your repository to require passing CI checks before a pull request can be merged. No exceptions, no excuses.

Doing this ensures that every pull request is tested and vetted before it joins the ranks of your codebase. It's like having a deputy who checks every cowboy's boots for spurs before letting them into the saloon.

The Best Practice: Merge Queues

Let's talk about the new sheriff in town: the merge queue. A merge queue is like a well-organized cattle drive, ensuring that every pull request is updated and tested against the latest code before it's merged. Here's how to set up your merge queue:

  1. Choose a Merge Queue Tool: There are several merge queue tools available, such as Mergify, Bors, and others. Pick fits your needs best and integrates well with your CI/CD pipeline.
  2. Configure Your Merge Queue: Set up your merge queue to automatically update and test pull requests before merging.
  3. Educate Your Team: Make sure your team knows how to use the merge queue and understands the benefits it brings.

Using a merge queue ensures that every pull request is updated and tested, not just against the last version of your code. 

The Merge Queue: A Safety Gate and Velocity Booster

In conclusion, using a merge queue is like putting up a sturdy gate at the entrance of your codebase corral. It checks every cowboy's boots for spurs, ensures they fit perfectly, and only lets them in when everything is correct. By doing this, you're reducing the need for git revert hoedowns, increasing developer velocity, and enhancing the developer experience.

So next time you reach for that git revert command, remember: there's a better way. Saddle up, partner, and ride the merge queue to cleaner, safer code pastures. Happy coding, you all!