GitHub: why updating the branch was refused
"Update branch" through GitHub's REST API is PUT /repos/OWNER/REPO/pulls/NUMBER/update-branch, which merges the head of the base branch into the pull request's branch. expected_head_sha is optional: the head you expect the branch to have, which GitHub's documentation says answers 422 when it does not match. GitHub's documentation names the statuses: 202 when the request is accepted, 403, and 422 when the request fails validation or the endpoint has been spammed. It does not list the 422 messages; the ones below are quoted from public reports, with GitHub's documented rules behind them (checked October 25, 2026).
PUT /repos/OWNER/REPO/pulls/NUMBER/update-branch
{"expected_head_sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"}
422: what GitHub says, and why
merge conflict between base and head: the base branch's new commits conflict with the pull request's branch, so GitHub cannot merge them in. GitHub's documentation says the branch can be updated from the pull request's page when there are no merge conflicts and it is behind the base branch; conflicts are resolved first.- The GitHub CLI:
gh pr update-branchcompares the branches first. When the pull request is not behind, it printsPR branch already up-to-dateand sends nothing. Otherwise it sendsupdatePullRequestBranchwith the head it read, merging, or rebasing with--rebase. On a conflict it shows onlyCannot update PR branch due to conflicts, not the GraphQL text (its source). In two public reports, both with--rebase, the conflict was inpnpm-lock.yaml: spurintel/javascript#75, EdV4H/usketch#818. Bring the base branch in locally, fix the conflict, and push. - Pick it by URL or branch:
gh pr update-branchtakes the pull request as a number, a URL or a branch, and-Ror--repowith[HOST/]OWNER/REPOselects another repository, as in the manual'sgh pr update-branch 23 --repo owner/repo(gh pr update-branch). There are no new commits on the base branch.: the pull request's branch already has every commit of the base branch, so there is nothing to merge. Public reports treat this answer as "already up to date".expected head sha didn't match current head ref:expected_head_shais no longer the branch's head: someone pushed to it after you looked. Withoutexpected_head_sha, GitHub takes the branch's current head.
To update a branch without passing commits you have not seen: Pull Request Inbox for GitHub, a plugin for JetBrains IDEs, sends the head commit you had on screen as expected_head_sha, and on 202 says that GitHub is merging the new commits and loads the pull request again.
403, 404
- 403
Resource not accessible by personal access token(orby integration): GitHub's list of permissions gives this endpoint to Pull requests with write access, for a fine-grained token (see which permission to add). A request on behalf of a GitHub App must also be able to write the contents of the head repository. - A protected head branch: GitHub's documentation says that you may not be able to use Update branch when the pull request's head branch is a protected branch.
- 404: the repository or pull request is not there for this token, which is also how GitHub answers a private repository the token cannot see.
- Whose write access counts: GitHub's documentation says that people with write permissions to the repository the head branch belongs to can update it. For a pull request from a fork, that is the fork, not the base repository; Update branch button not shown covers Allow edits from maintainers (GitHub's keeping your pull request in sync with the base branch).
202: accepted
GitHub answers 202 Accepted with a message and a url: it took the request, and the merge commit comes onto the branch after that. Load the pull request again to see it. Through the REST API the branch is always updated with a merge commit; the pull request's page also offers Update with rebase.
What to do
- A merge conflict: merge the base branch into the pull request's branch locally (
git fetch origin,git switch HEAD-BRANCH,git merge origin/BASE), resolve the conflicts, commit and push. - No new commits: nothing to do; load the pull request again.
- The head moved: load the pull request again, look at the new commits, then update again with the new head in
expected_head_sha. - See the new commits through the API:
GET /repos/OWNER/REPO/pulls/NUMBER/commitslists the pull request's commits, at most 250 of them, withper_pageup to 100 (GitHub's list commits on a pull request). - More than 250 commits: GitHub points to the list commits endpoint for the complete list:
GET /repos/OWNER/REPO/commitswithshaset to the SHA or branch to start listing from, and the repository's default branch whenshais left out (list commits). - The merges endpoint instead:
POST /repos/OWNER/REPO/mergeswithbaseset to the pull request's branch andheadset to the base branch makes a merge commit on the pull request's branch. It answers 201 with the merge commit, 204 when it is already merged, 404 when the base or head does not exist, and 409 when there is a merge conflict (GitHub's REST documentation for branches). - One file through the contents endpoint:
PUT /repos/OWNER/REPO/contents/PATHwithbranchset to the pull request's branch writes the file there as a new commit (withoutbranch, to the default branch). To replace a file that is already there,shahas to be the blob SHA of that file, whichGET /repos/OWNER/REPO/contents/PATH?ref=BRANCHreturns; without it the answer is 422Invalid request. "sha" wasn't supplied.GitHub's documentation also says that this endpoint and Delete a file conflict when they run in parallel, so call them one after another; 409 Conflict is among this endpoint's answers (GitHub's REST documentation for repository contents). Public reports: googleapis/release-please-action#959, PoloNX/SwitchU-Themes#53. - 403: give the token Pull requests with write access, or ask someone who can push to the branch.
- To rebase instead, through the API: GraphQL's
updatePullRequestBranchtakesupdateMethod: REBASE(MERGEwhen omitted). Its optionalexpectedHeadOidis described as the head ref oid for the upstream branch. It is the same mutation the GitHub CLI sends with--rebase(GitHub's updatePullRequestBranch and UpdatePullRequestBranchInput). - The pull request's node ID:
pullRequestIdis the Node ID of the pull request, not its number.gh pr view NUMBER --json id,headRefOidreturns that ID together with the head commit to pass asexpectedHeadOid(GitHub's public GraphQL schema; gh's query_builder.go). - After the update, an approval can go: when branch protection dismisses stale pull request approvals, GitHub records the diff each approval was given on, and dismisses the approval when the diff changes; it names clicking Update branch as one example. Someone then has to approve again before the merge (GitHub's require pull request reviews before merging; see approvals that do not count).
- After an update from a workflow, the runs wait: when a workflow updates the branch with the repository's
GITHUB_TOKEN, the runs from the resultingpull_requestevent wait in an approval-required state: the merge box shows a banner, and someone with write access starts them with Approve workflows to run. Updated with a GitHub App installation access token or a personal access token, they run without approval (GitHub's GITHUB_TOKEN; see GitHub checks not running on a pull request a workflow created). - After Update with rebase, pull with --rebase: the rebase rewrites the branch's commits on GitHub, so a local copy of the branch can no longer fast-forward to it. With neither
pull.rebasenorpull.ffset,git pullstops withfatal: Need to specify how to reconcile divergent branches.Pulling withgit pull --rebaseputs the commits you have not pushed on top of the new branch (Git's builtin/pull.c and git pull).
GitHub pull requests in IntelliJ IDEA
Pull Request Inbox for GitHub, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, shows Update the branch on the pull request's page only when the target branch has commits the pull request does not have yet, and the two do not conflict. It sends the head commit you had on screen as expected_head_sha, so the branch is not updated past commits you have not seen. On 202 it says that GitHub is merging the target branch's new commits into the branch, and loads the pull request again; when GitHub refuses, it shows GitHub's words. The review inbox, diffs and conversations are free; approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).
Get it on JetBrains Marketplace
GitHub is a trademark of GitHub, Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by GitHub, Inc. or JetBrains.
More: GitHub merge refused (405, 409) · GitHub review refused (422) · GitHub search 422 "Validation Failed" · "Resource not accessible by personal access token" · 401 "Bad credentials" · "Resource protected by organization SAML enforcement" · "API rate limit exceeded" · GitHub diff 406 "too_large", 3,000 files · GitHub line comment 422 "must be part of the diff" · GitHub pull request not created (422, 403) · GitHub auto-merge refused · GitHub draft, ready for review or close refused · GitHub conversation not resolved · GitHub checks not shown (check runs 403) · GitHub file contents not read · GitHub compare refused (404, 422) · GitHub comment or reply refused (403 locked, archived) · GitHub merge method not allowed (405) · GitHub branch not found (404, 301) · GitHub Enterprise Server not reached · GitHub review request not shown · GitHub pull request list incomplete · GitHub 404 Not Found, renamed repositories (301, 307) · GitHub line comment outdated or not on the diff · GitHub pull requests not updating, notifications late · GitHub suggested change cannot be applied · GitHub required check stuck at "Expected" · GitHub code owner review required · GitHub merge blocked by unresolved conversations · GitHub merge blocked by unsigned commits · GitHub branch that merges through a merge queue · GitHub merge waiting for an approval of the most recent push · GitHub merge waiting for code scanning results · GitHub merge waiting for code quality results · GitHub merge blocked by a code coverage threshold · GitHub merge blocked by license compliance results · GitHub branch locked or its updates restricted · GitHub branch not deleted after merging · GitHub merge waiting for a team's approval (Required reviewers) · GitHub merge blocked by secret scanning alerts · GitHub stacked pull request not merging · GitHub push blocked by push rules · GitHub merge blocked by commit metadata rules · GitHub force push blocked · GitHub issue not closed by a merged pull request · GitHub pull request not checked out locally · GitHub pull request has merge conflicts · GitHub changes requested and dismissing a review · GitHub co-author not credited for a commit · GitHub dependency review check failed · GitHub Dependabot not rebasing its pull request · GitHub fork not syncing with upstream · GitHub pull request base branch not changing · GitHub pull request not reverting · GitHub pull request template not showing · GitHub pull request labels or assignees not added · GitHub pull request not closing or reopening · GitHub push blocked by push protection · GitHub pull request comment hidden · GitHub pull request blocked until deployments succeed · GitHub team review request replaced by members · GitHub pull request file no longer marked Viewed · GitHub pull request marked merged without being merged · GitHub Copilot review does not count as an approval · GitHub checks not running on a pull request a workflow created · GitHub Update branch button not shown on a pull request · GitHub checks failing on a Dependabot pull request · GitHub checks failing on a pull request from a fork · GitHub checks skipped by [skip ci] in a commit message · GitHub checks gone after the retention period · GitHub code review limits in a public repository · GitHub pull requests turned off or limited in a repository · GitHub checks run on every pull request in a stack · GitHub pull request showing commits already squash merged · GitHub pull request not showing a file diff · GitHub push to a pull request branch from a fork refused · GitHub check cancelled on a pull request · GitHub Rebase and merge not available · GitHub merge commit message not what you expected · GitHub pull request shows every line changed · GitHub API request timed out · GitHub pull request image or document diff not shown · GitHub review request refused (422) · GitHub pull request from Copilot: checks not running, approval not counted · GitHub push refused: GH006 and GH013 on a protected branch · GitHub "At least 1 approving review is required", approvals that do not count · GitHub pull request plugins for IntelliJ IDEA, compared · 日本語