Using Graphite with Mergify

Learn how you can use Graphite and Mergify together.


Graphite is a modern code review tool designed for fast-moving teams. It helps engineers write and review smaller pull requests (PRs), stay unblocked, and ship faster. In this documentation, we explain how to use Mergify with Graphite and highlight some important configurations.

  • A GitHub repository ready for Mergify usage.

  • Graphite installed and configured for your project. If you are not familiar with Graphite, we recommend following their quick start guide.

In the following step we will use a sample stack with our “trunk branch” named main and three branches A, B and C with their corresponding pull requests

o C
│
o B
│
o A
│
o main
│
:

Step 1: Configuring Your Repository

Section titled Step 1: Configuring Your Repository

To ensure seamless integration between Mergify and Graphite, you need to activate the Automatically Delete Head Branches setting on your GitHub repository. Enabling this setting allows GitHub to automatically delete the head branch upon pull request merge and change the base branch of upstack pull requests to the branch in which the PR was merged.

For example, in our sample stack, when PR A is merged into main, enabling this setting will delete branch A and change the base branch of PR B from A to main.

To activate Automatically delete head branches, follow the steps outlined in the GitHub documentation: Managing the automatic deletion of branches.

To ensure that Mergify only merges pull requests that are at the bottom of their stack. In the Mergify configuration file, you have to set a condition on the base attribute to be equal to the name of your trunk branch (main in our sample stack).

Here is a sample of what your Mergify configuration file could look like for our sample stack:

queue_rules:
  - name: default
    queue_conditions:
      - base=main

This makes sure that if a user queues by mistake the pull request B while A is not yet merged, the pull request B won’t be queued.

Now that everything is set up, you can queue your pull request. When Mergify is done merging pull request A into main, GitHub will delete branch A and set main as the base branch for pull request B. You can then queue the pull request B at its turn.