GitHub: why the branch was not found
One branch is read with GET /repos/OWNER/REPO/branches/BRANCH; GitHub's documentation lists its answers as 200, 301 "Moved permanently" and 404 "Resource not found", and says the name cannot contain wildcard characters (the GraphQL API takes those). All branches are listed with GET /repos/OWNER/REPO/branches, 30 a page unless per_page asks for up to 100; protected=true lists only the branches protected by branch protections or rulesets, and protected=false only the others (checked October 25, 2026).
GET /repos/OWNER/REPO/branches/feature-x → 404 GET /repos/OWNER/REPO/branches/master → 301 Location: …/branches/main
GitHub's answers and the reasons
- 404: there is no branch by that name on GitHub: it was never pushed, it was pushed under another name (a local branch can track an upstream branch with a different name), or it was deleted, for example after its pull request was merged. A repository the token cannot see answers 404 too.
- A name that cannot be a branch: Git has rules for reference names, so some names are never on GitHub: no part between slashes may begin with a dot or end with
.lock, and a name cannot contain two dots in a row, a space,~,^,:,?,*,[, a backslash or@{, cannot begin or end with a slash, and cannot end with a dot.git check-ref-format --branch NAMEchecks a name and exits with a non-zero status when it is not acceptable; its rule for branch names is stricter, for example a dash at the start is refused (git's git check-ref-format). - 301 to another branch: GitHub's documentation on renaming says URLs that contain the old branch name are redirected to the renamed branch. A public report from 2026, measured with redirects not followed, found
GET …/branches/masteranswering 301 with aLocationnaming the repository's current default branch (such asmain,developor a version branch) in repositories without amaster; other names that were not there, such astrunk,developanddev, answered 404. A client that follows redirects gets 200 describing a branch it did not ask for, so compare thenamein the answer with the name asked. - A renamed branch: the documentation says renaming updates branch protection policies and the base branch of open pull requests, closes an open pull request whose head is the renamed branch, and is not followed by a
git pullof the old name; raw file URLs are not redirected either. - Right after a rename through the API:
POST /repos/OWNER/REPO/branches/BRANCH/renamewithnew_nameanswers at once, but the rename may take extra time in the background, and you cannot push to the old branch name until it finishes. It needs push access to the branch, and for the default branch also admin or owner permissions; a fine-grained token also needs the administration:write repository permission to rename the default branch (GitHub's REST documentation for branches). - Only 30 branches: a list stops at one page. A public report from 2019 got 30 branches from a repository with more, with the next page named in the
Linkheader. - Through the Git references API: Get a reference,
GET /repos/OWNER/REPO/git/ref/heads/BRANCH, takesheads/BRANCHfor a branch and answers 404 when it does not match an existing ref. List matching references,GET /repos/OWNER/REPO/git/matching-refs/heads/BRANCH, returns an array, and when the ref does not exist but existing refs start with it, it returns those:heads/featurecan bring backheads/feature-x, so check eachrefin the answer.
To catch an unpushed branch before you open the pull request: Pull Request Inbox for GitHub, a plugin for JetBrains IDEs, checks that GitHub has the branch, and on a 404 says that it is not on GitHub yet and offers the IDE's push dialog.
What to do
- See what is on GitHub:
git ls-remote --heads originlists the remote's branches;git branch -vvshows which upstream branch each local branch tracks. - Only one branch cloned:
git clone --single-branchclones only the history leading to the tip of a single branch, and further fetches into that repository update only the remote-tracking branch for that branch (Git's git clone). - In the browser: View all branches in the branch dropdown opens the branches page, with Yours (the branches you pushed to, in repositories you can push to), Active (committed to in the last three months), Stale (no commits for three months, oldest first) and All. Its search field looks for part of the name, case-insensitively, with no other query syntax (GitHub's viewing branches in your repository).
- Push it:
git push -u origin BRANCHpushes the branch and makes it the upstream. - The same name on a remote: when there is no local branch by that name but a tracking branch with a matching name exists in exactly one remote,
git switch BRANCHworks asgit switch -c BRANCH --track REMOTE/BRANCH. If several remotes have it,checkout.defaultRemote(for example origin) picks one;--guessis the default, and--no-guessturns it off (Git's git switch). - After a rename: the documentation updates a local clone with
git branch -m OLD-BRANCH-NAME NEW-BRANCH-NAME,git fetch origin,git branch -u origin/NEW-BRANCH-NAME NEW-BRANCH-NAMEandgit remote set-head origin -a. - A branch deleted on GitHub still in your clone: Git keeps the remote-tracking branches of branches the remote has deleted.
git fetch --prune originremoves them while fetching,git remote prune originremoves them without fetching, andgit config --global fetch.prune truemakes every fetch do it (git's pruning). - Reading the API: follow the
Linkheader withper_page=100until there is no next page, and when redirects are followed, check that the branch'snameis the one asked. - A token that reads branches: List branches and Get a branch work with GitHub App user access tokens, GitHub App installation access tokens and fine-grained personal access tokens, with the Contents repository permission (read); without authentication or that permission, they can be used only when only public resources are requested (GitHub's List branches).
- Creating a pull request into a branch that is not there: see GitHub pull request not created (422, 403).
- Every page at once:
gh api --paginate repos/OWNER/REPO/branches --jq '.[].name'requests the pages one after another until there are no more, and prints the names (GitHub CLI's gh api). - In GraphQL: a repository's
ref(qualifiedName: "refs/heads/BRANCH")fetches one ref; fully qualified matches such asrefs/heads/masterare checked before short name matches such asmaster.refs(refPrefix: "refs/heads/", query: "NAME", first: 100)filters the branches by name, and itstotalCountis the number of them (GitHub's Repository object).
In IntelliJ IDEA: branches are picked from the clone, and the push is decided there
Checked in the IntelliJ IDEA source on October 31, 2026: GHPRCreateViewModel.kt, GHPRCreateComponentFactory.kt, GHPRRepositoryDataServiceImpl.kt, MergeDirectionComponentFactory.kt, GitPushUtil.kt.
Next to the branches of a new pull request, a warning icon can show one of these tooltips:
There is no remote branch for 'BRANCH'.
New remote branch will be created on 'REMOTE'.
Local branch is not in sync with remote.
'BRANCH' branch will be synced with 'REMOTE/BRANCH'.
The first means the local branch has no target to push to. The target is the branch the remote's push refspec names, or else its upstream branch, but only when the upstream is on the same remote and has the same name. A branch whose upstream has another name (feature tracking origin/me/feature), with no push refspec, has no target, so creating the pull request asks for a name in New Remote Branch for Pull Request, with the local name filled in.
The second means the local branch's commit differs from the commit the clone has for the target branch. On Create, the IDE pushes, without the push dialog, only when those commits differ; it does not ask GitHub whether the branch is there. A branch deleted on GitHub whose remote-tracking branch is still in the clone at the same commit is therefore not pushed again, and the request to create the pull request names a branch GitHub no longer has. When the push or the request fails, it shows Failed to create a pull request.
The base branch list holds the remote-tracking branches the local clone has for that remote, so a branch that is on GitHub but has not been fetched is not in it. The base starts at the clone's remote-tracking branch named after the repository's default branch on GitHub (GraphQL defaultBranchRef); when the clone has no such branch, it reads Select….
GitHub pull requests in IntelliJ IDEA
Pull Request Inbox for GitHub, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, checks before creating a pull request that GitHub has the branch; when GitHub answers 404 it says the branch is not on GitHub yet and offers the IDE's push dialog. It looks for the name the branch was pushed under when its upstream is on the same remote (git push -u origin feature:me/feature), and otherwise for the local name. The target field offers the branches on GitHub (read 100 a page, up to 1,000); with more, or when they cannot be read, it takes any name. When GitHub answers for the name with another branch, as for master in the report above or a renamed branch's old name, it does not count the branch as pushed: it names the branch GitHub sent it on to and offers the push dialog. 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 branch update refused (422) · 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 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 · 日本語