Skip to content
Source
Sign inSign up

Merge when checks pass

Issues and pull requests / Pull requests

Merge a pull request when its checks pass

Your checks still run, and you do not want to wait to click merge. Turn on merge when ready, and the pull request merges by itself when its checks pass.

9 min read

You need write access.

An up-to-date branch rule checks whether the head contains the current base commit, including for a fork. This check reads commit history. It does not compare files. If the history exceeds the read limit, the result is unknown and the rule blocks the merge. Follow the reason in the merge box, then push the updated branch.

Tip

Do several pull requests go into the same base branch? Add them to the merge queue. It merges them one at a time, each when its checks pass. It updates a branch with the base branch first when a branch rule requires it, or when the branch has conflicts.

1. Pick how it merges

  1. Open the pull request.
  2. In the merge box in the right column, pick Create a merge commit, Squash and merge or Rebase and merge. See Pick how a pull request merges.

2. Turn on merge when ready

  1. Click Merge when ready. For a squash, the button says Squash and merge when ready, and for a rebase Rebase and merge when ready.
  2. If necessary, change the commit title and message. Then click Confirm merge when ready.
The merge box of a pull request whose checks still run, with the Merge when ready button

In a terminal:

src pr merge 7 --auto --squash

For a merge commit, use --merge in place of --squash, and for a rebase --rebase.

The merge box now says Merge when ready is on. It shows who turned it on, how it merges, and what it waits for.

Note

The button says Merge when ready while checks run or fail, the branch rules refuse the merge, or the branch has conflicts. When every check passed, it says Merge pull request, Squash and merge or Rebase and merge, and it merges at once.

3. Let it merge

When every check on the newest commit passed and nothing else blocks the merge, the forge merges the pull request as you. It uses your method and your commit text.

Until then, merge when ready stays on:

  • If a required check fails, the box says Waits for the required check ci/test to pass., with Open the job log. A re-run that passes, or a new push whose checks pass, merges it.
  • If the merge is refused for a cause that can go away by itself, the box says Waiting: with the reason. It tries again by itself. For example, GitHub's base branch moved.
  • If someone pushes to the branch in this repository, it stays on. Then it waits for the checks of the new commit.

Done

The pull request merges by itself when its checks pass, with your method and your commit text. The timeline shows who turned merge when ready on. When the pull request merges, the forge also stops the CI and the agents that still work on it. See The work that stops at the merge or the close.

Approve and merge in one click

If you can review the pull request and nobody approved it yet, the merge button also approves it.

  • When every check passed, the button says Approve and merge (or Approve, squash and merge, Approve, rebase and merge). It merges at once.
  • When checks still run or the pull request is not ready yet, the button says Approve and merge when ready (or Approve, squash and merge when ready, Approve, rebase and merge when ready). It turns on merge when ready.
  1. Click Approve and merge (or Approve and merge when ready).
  2. Click Confirm approve and merge (or Confirm approve and merge when ready). The forge records your approval, then merges or turns on merge when ready.
  • To merge without your approval, clear Approve it first before you confirm.
  • If the forge refuses the approval, it does not merge and does not turn on merge when ready.
  • In a stack whose merge lands more than one pull request, the button stays a plain merge.

Turn it off

Click Turn off in the merge box. In a terminal, run:

src pr merge 7 --disable-auto

The person who turned it on can turn it off, and so can people with write access.

When it turns off by itself

Merge when ready turns itself off in these cases:

  • The pull request closes.
  • Someone without write access pushes to it. Each push to a fork counts as such a push, because the forge cannot see who pushed there. A CI fixup() commit in a fork counts too, unless a person with write access to this repository applied it.
  • You can no longer merge. When the pull request is ready, the forge checks your permission again.
  • An agent turned it on, and the base is the default branch. An agent never merges into the default branch.

It also turns off for a cause that needs a person. The box then shows Merge when ready turned off, with the reason and the fix:

  • The branch has conflicts with its base branch. Resolve the conflicts first. See What counts as a conflict.
  • The person who turned it on has no working GitHub connection.
  • The pull request points at LFS objects that are not stored here.

Fix the cause, then click Turn on again. Each fix is in Merge when ready did not merge.

  • The author and the people who can merge read the exact reason. Other people read Merge when ready is waiting. or Merge when ready turned off. A maintainer can turn it on again.
  • The timeline shows who turned merge when ready on or off. When it turned off by itself, the timeline says why.

What counts as a conflict

The forge merges the two branches as git does: file by file, and line by line in a file that both branches changed. A conflict is a change that it cannot merge by itself:

  • Both branches changed the same lines of a file.
  • One branch changed a file, and the other deleted it.
  • Both branches changed a binary file, or a file of more than 8 MiB.

Renamed files

The forge finds renamed files as git diff -M does: a file that moved and kept at least half of its content.

  • One branch renamed a file, and the other edited it. The edits merge into the file at its new path, with no conflict.
  • Both branches renamed the file to the same path. The edits merge at that path.
  • The branches renamed the file to two different paths. This is a conflict.
  • One branch renamed the file, and the other deleted it. This is a conflict.
  • One branch renamed the file to a path where the other branch added a different file. This is a conflict.

The forge finds renamed files, not renamed folders. If one branch moves a folder and the other adds a new file to the old folder, the new file stays in the old folder. Move it after the merge.

Note

In a very large change, the forge finds only the files that moved with no edits. For example, this happens when a branch deleted more than 1,000 files or added more than 1,000 files.

On a repository with GitHub sync

A pull request that sync brings in

A pull request from GitHub sync waits for other checks:

  • Sync does not start CI for it. Merge when ready waits until someone clicks Run checks on the pull request. Run checks also approves its GitHub Actions and runs them again. See Run checks.
  • Merge when ready also waits for its checks on GitHub. They show in the On GitHub group of the checks. See Checks from GitHub.

Its merge works differently too:

  • The merge goes to GitHub, the same as a click on Merge.
  • Each new commit on GitHub turns merge when ready off.
  • If its base branch is not a branch that sync brings down, it cannot merge here. The merge button is off before you click it, and the box links to the pull request on GitHub. Merge it there.
  • If GitHub's base branch moved, the merge is refused. Sync brings the branch down by itself, and the page updates. Then merge again. Merge when ready waits and tries again by itself.

A pull request that you open here into a release branch

On a repository with GitHub sync, a pull request that you open here into a release branch opens on GitHub too. This happens when you connected GitHub and the head is a branch of this repository. Then:

  • The merge goes to GitHub, so the checks and reviews that GitHub requires apply.
  • Each push here to its head branch goes to GitHub too.
  • Its checks on GitHub show in the On GitHub group of the checks, and merge when ready waits for them.

If a pull request into a release branch is only here, its merge is refused. Click Open on GitHub on its page, or run src github-sync open 7. Then merge. The details are in Pull requests opened here.

Later: REST and MCP

An agent or a script does the same work over REST or MCP, with the same rules. The REST paths are under /api/v1/repos/{owner}/{repo}.

You want toRESTMCP tool
Read the required checks, with the job of each oneGET /pulls/{n}/checksget_pull_request_checks
Turn on merge when readyPUT /pulls/{n}/auto-merge, with { "merge_method", "commit_title", "commit_message" }enable_pull_request_auto_merge
Turn off merge when readyDELETE /pulls/{n}/auto-mergedisable_pull_request_auto_merge

For merge when ready:

  • merge_method is merge, squash or rebase, and merge when you leave it out. The commit text is the text of the pull request page when you leave it out. A rebase takes no commit text.
  • If the pull request is ready already, it merges a moment later.
  • The answer is { "number", "state", "autoMerge" }. autoMerge is { "enabledBy", "method", "enabledAt" }, or null when it is off.
  • GET /pulls/{n} has the same autoMerge, plus autoMergeRefusal: why merge when ready did not merge yet or turned off (reason, at, temporary, check), or null. People who can merge and the author get the exact reason, everyone else a general one.
  • A pull request synced from GitHub also has githubMerge: { "refusal" } when it cannot merge here.

Each required check of GET /pulls/{n}/checks has jobId, the job that its reason is about. The log of that job is at /@<owner>/<repo>/jobs/<jobId>. jobId is null for a check that passed, when its reason names no job that ran, and for a hidden check.

The merge queue has its own routes. See In a terminal or from an agent. Use the REST API has the other routes.