{"record":{"id":"37eb3b8260cc061d","repo":"theonedev/onedev","slug":"branch-not-found-branchname","errorCode":null,"errorMessage":"Branch not found: ${branchName}","messagePattern":"Branch not found: (.+?)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/RepositoryResource.java","lineNumber":139,"sourceCode":"\t\t}\n\n\t\treturn Response.ok().build();\n\t}\n\n\t@Api(order=20, description=\"Get specified branch\")\n\t@Path(\"/{projectId}/branches/{branch:.*}\")\n\t@GET\n\tpublic RefResponse getBranch(\n\t\t\t@PathParam(\"projectId\") Long projectId, \n\t\t\t@PathParam(\"branch\") @Api(example=\"test-branch\") String branchName) {\n\t\tProject project = projectService.load(projectId);\n\t\tif (!SecurityUtils.canReadCode(project)) {\n\t\t\tthrow new UnauthorizedException();\n\t\t}\n\n\t\tRefFacade ref = project.getBranchRef(branchName);\n\t\tif (ref == null)\n\t\t\tthrow new NotFoundException(\"Branch not found: \" + branchName);\n\n\t\tRefResponse response = new RefResponse();\n\t\t\n\t\tresponse.refName = ref.getName();\n\t\tresponse.commitHash = project.getRevCommit(ref.getObjectId(), true).getName();\n\t\t\n\t\treturn response;\n\t}\n\n\t@Api(order=30, description=\"Create a new branch\")\n\t@Path(\"/{projectId}/branches\")\n\t@POST\n\tpublic Response createBranch(@PathParam(\"projectId\") Long projectId, @NotNull CreateBranchRequest request) {\n\t\tProject project = projectService.load(projectId);\n\t\tUser user = SecurityUtils.getUser();\n\t\tif (!SecurityUtils.canWriteCode(project)) \n\t\t\tthrow new UnauthorizedException();\n\t\telse if (project.getBranchRef(request.getBranchName()) != null) ","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/RepositoryResource.java#L121-L157","documentation":"GET /repositories/{projectId}/branches/{branchName} throws NotFoundException with message 'Branch not found: {branchName}' when project.getBranchRef returns null, i.e. no ref matching that branch exists in the repository.","triggerScenarios":"Querying a branch name that was deleted; typo in the branch name; using full ref name (refs/heads/main) where short name is expected; querying before the branch was pushed.","commonSituations":"CI referencing renamed branches; stale caches of branch lists after branch deletion; case-sensitivity mismatches (git refs are case-sensitive on Linux).","solutions":["Call GET /{projectId}/branches and pick an exact name from the list","Fix spelling/casing of branchName to match an existing branch","Create/push the branch before querying it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"List<String> branches = GET(\"/repositories/\" + projectId + \"/branches\");\nif (!branches.contains(branchName))\n    throw new IllegalArgumentException(\"Branch does not exist: \" + branchName);","typeGuard":null,"tryCatchPattern":"try {\n    ref = client.getBranch(projectId, branchName);\n} catch (NotFoundException e) {\n    // fall back to default branch or refresh branch list\n}","preventionTips":["Validate branch names against the branches list endpoint first","Strip refs/heads/ prefixes; send short branch names","Re-fetch branch lists after renames/deletions before calling"],"tags":["rest","git","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}