Why You Should Be Using a Merge Bot in GitHub

Why You Should Be Using a Merge Bot in GitHub

Julien Danjou

It can be tedious and frustrating merging so many pull requests when you have a large open-source project and several developers working on it at once.

All that merging takes up your valuable time. You have to review code yourself—or assign people to it—and rebase your branches periodically, among other things.

Well, no longer will you have to concern yourself with these tasks if you get yourself a GitHub merge bot.

What is a merge bot?

When you have several open-source project contributors, they need to experiment with the code without harming the main project repository. Thus, they can clone the main source code repository and mess around with the code in their local development environment.

A pull request occurs when a project contributor finishes with their code and wants to implement their changes into the actual project.

Usually, the project maintainer has to review this code manually (or assign someone to do it) and make changes or send it back for revisions before merging it in.

As you might expect, this can become overwhelming on large projects with multiple contributors.

A merge bot is simply a bot on GitHub that helps you merge these pull requests automatically.

Let’s look at some benefits of using a merge bot in GitHub.

Benefits of using merge bots in GitHub

Save time

As with anything that uses automation, the biggest benefit of using a bot for a git merge is the time you’ll save on pull request approval stuff.

Merge bots let you set rules that instruct it to take various actions depending on your desired criteria. All you have to do is sit back and watch the bot go to work for most pull requests.

Reduce errors

Humans make errors on occasion. When you have several pull requests demanding your attention at once, the chances that you’ll make a mistake increase—especially if you’re trying to get through all the pull requests in a timely fashion.

For example, you may accidentally merge pull requests that aren’t ready for merging yet. This could cause all sorts of problems with the main project and create a headache for you.

By using a merge bot in GitHub, however, you can (again) set rules for merging pull requests on autopilot. You can write rules defining when to merge the pull request, ask for a code review, and many other actions.

Improve prioritization

Not all pull requests are created equal. Some are more urgent than others.

For example, you might have one person working on a mission-critical feature. Meanwhile, other contributors are merely messing around with some code to see if they can get some exciting but unnecessary feature to work right.

Perhaps the latter individuals finish and submit their pull request a couple of minutes before the former, and you already have some other non-urgent requests to deal with.

Many merge bots let you set priorities in the merge queue to solve this. You can make sure that mission-critical feature is attended to before the dozen non-urgent pull requests.

If the vital feature needs revisions, you can send it back out as soon as possible. Otherwise, it’ll be first in line for merging.

Stay updated

Kicking back and watching your merge bot go to work feels nice, but you might still feel anxiety about letting things run without any oversight from yourself.

No worries—merge bots like Mergify update the status of pull request merges in real time, and they even tell you which of your criteria matched.

Live Mergify report

Automate pull requests with Mergify

Pull requests are necessary to successfully manage open-source projects, but they’re repetitive. As you can see, a good merge bot can do plenty to reduce this toil and help you focus on more important matters.

If you’re looking for a merge bot that takes all the work out of approving and merging pull requests into your main GitHub project repository, Mergify can help.

All you have to do is define the rules used to merge pull requests in YAML, then enable Mergify and let it do the work for you. Mergify even lets you prioritize pull requests through the merge queue so you can implement the most urgent features first.

Let's say you want to merge a pull request when your CI passes and the code has been approved.

pull_request_rules:
  - name: automatic merge
    conditions:
      - check-success=test
      - "#approved-reviews-by>=1"
    actions:
      merge:
        method: merge

With this Mergify configuration, your pull request is automatically merged when the CI passes and the number of positive reviews is greater than 1.

The best part? Mergify is free for open-source projects, and it only takes one click to add Mergify to your GitHub. Sign up for Mergify today—linking it to your GitHub is as easy as one click.