Forgejo and Gitea: why the merge was refused
When a merge through the API (POST /api/v1/repos/OWNER/REPO/pulls/NUMBER/merge) fails, Forgejo and Gitea answer 405 or 409, and the JSON's message says why. From the source of both (MergePullRequest in routers/api/v1/repo/pull.go, and the checks in services/pull): 405 means that a check stopped the merge before it started, and 409 that the server tried and the merge failed, or that the branch moved since you looked. The wording below is the current source of both; older servers may word it differently.
405: a check stopped it
The checks run in this order, and the first one that fails answers:
- Already merged: Gitea says
The PR is already merged; Forgejo answers with an empty message. A closed pull request answers 404 instead. User not allowed to merge PR: your account may not merge into the target branch. It needs write access, and a branch protection rule can narrow who may merge.Work in progress PRs cannot be merged: the title starts with a work-in-progress prefix (by defaultWIP:or[WIP]). Remove it to mark the pull request ready.Please try again later: the server has not marked the pull request mergeable. In the source this answer comes whenever the pull request is not in the mergeable state, so conflicts answer this too, not 409, and so does a pull request that the server is still checking after a push.- Branch protection (Forgejo writes
not allowed to merge [reason: …], Gitea the reason alone):Not all required status checks successful,Does not have enough approvals,There are requested changes,There are official review requests,The head branch is behind the base branch,Changed protected files, and in GiteaThere are missing code owner reviews. Administrators may skip these withforce_merge, where the rule allows it. - Signed commits: the target branch requires signed commits and the merge would not be signed. Gitea also refuses when not all of the pull request's commits are verified.
- The merge style: Forgejo says
squash is not an allowed merge style for this repository(with the style you sent inDo): the repository's settings do not allow that style.
To see where a pull request stands, read it:
curl -H "Authorization: token your-token" https://codeberg.org/api/v1/repos/OWNER/REPO/pulls/42
mergeable is false while the server is checking it, while it conflicts, after an error in that check, and while it is a work in progress. Use your own server's address instead of codeberg.org. Asking with merge_when_checks_succeed instead schedules the merge for when the checks pass (201): the branch protection checks do not stop that request. See what a scheduled merge waits for, and what still refuses it.
409: the merge was tried and failed
head out of date: you senthead_commit_id, the head you reviewed, and the branch has another head now. Someone pushed after you looked.- No message, but
Style,StdOutandStdErr: git found conflicts while merging (or while rebasing, for the rebase styles), or the branches share no history. The checks had not seen it yet. merge push out of date: the target branch moved while the server was merging.PushRejected with remote message: …: a hook on the server refused the merge's push; the rest is the hook's words.- Asking with
merge_when_checks_succeedwhen a merge is already scheduled also answers 409.
A 500 with an empty message, once the other checks pass, means the pull request depends on an issue or pull request that is still open: the server shows that reason only to administrators. Close that one or remove the dependency (more on it).
What to do
- Please try again later: right after a push, wait a few seconds and merge again. If
mergeablestays false, resolve the conflicts: merge or rebase the target branch into yours in a clone and push. - Branch protection: get what the reason names (approvals, passing checks, a reviewer's new review), update the branch when it is behind, or ask for the merge when the checks succeed.
- User not allowed to merge PR: ask someone who may merge, or check the target branch's protection rule in the repository's settings.
- head out of date: look at the new commits, then merge with the new head.
- Conflicts (409) or merge push out of date: read the pull request again and resolve the conflicts, or simply try again.
Forgejo and Gitea pull requests in IntelliJ IDEA
Pull Request Inbox for Forgejo and Gitea, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, shows a pull request's merge checks before you merge, with the ones that block the merge first: work in progress, approvals against the count the branch requires, requested changes, the required checks, conflicts, a target branch with new commits, and whether the branch lets your account merge. It merges the head commit you had on screen. When the server answers "Please try again later" right after a push, it asks again for a few seconds. When the server refuses, it says so: for 405, that the server cannot merge it now, with the server's words, and to see the merge checks; for 409 "head out of date", that the branch changed and to refresh; from version 1.0.14, for the other 409s, that the branches conflict or share no history, or the server's words; from version 1.0.17, for a 500 with no message, that an open dependency blocks the pull request. It can also merge when the checks succeed and update the branch. Reading is free; approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).
Forgejo, Gitea and Codeberg are names of their respective owners; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by the Forgejo project, Codeberg e.V., the Gitea project or JetBrains.
More: Forgejo and Gitea merge when checks succeed refused (405, 409, 500) · Forgejo and Gitea required checks (missing, skipped, patterns) · 404 "The target couldn't be found." and "not found" · 401 "token is required" and unknown tokens · "token does not have at least one of required scope(s)" · Forgejo and Gitea review refused (422) · Forgejo and Gitea branch update refused (403, 409, 422) · Forgejo and Gitea pull request not created (409, 422, 403) · Forgejo and Gitea comment refused (403, 422, 400) · Forgejo and Gitea search refused (400, 422) · Forgejo and Gitea pull request files (pages of 50, changed_files) · Forgejo and Gitea pull request plugins for IntelliJ IDEA, compared · 日本語