{"record":{"id":"d39a23c47426e6d5","repo":"mislav/hub","slug":"unsupported-flag-orphan-when-checking-out-pull-r","errorCode":null,"errorMessage":"Unsupported flag --orphan when checking out pull request","messagePattern":"Unsupported flag --orphan when checking out pull request","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/checkout.go","lineNumber":156,"sourceCode":"\t\t\tremote = project.GitURL(\"\", \"\", true)\n\t\t\tmergeRef = fmt.Sprintf(\"refs/heads/%s\", pullRequest.Head.Ref)\n\t\t}\n\n\t\tif mc, err := git.Config(fmt.Sprintf(\"branch.%s.merge\", newBranchName)); err != nil || mc == \"\" {\n\t\t\targs.After(\"git\", \"config\", fmt.Sprintf(\"branch.%s.remote\", newBranchName), remote)\n\t\t\targs.After(\"git\", \"config\", fmt.Sprintf(\"branch.%s.merge\", newBranchName), mergeRef)\n\t\t}\n\t}\n\treturn\n}\n\nfunc sanitizeCheckoutFlags(args *Args) error {\n\tif i := args.IndexOfParam(\"-b\"); i != -1 {\n\t\treturn fmt.Errorf(\"Unsupported flag -b when checking out pull request\")\n\t}\n\n\tif i := args.IndexOfParam(\"--orphan\"); i != -1 {\n\t\treturn fmt.Errorf(\"Unsupported flag --orphan when checking out pull request\")\n\t}\n\n\treturn nil\n}\n\nfunc replaceCheckoutParam(args *Args, checkoutURL string, replacement ...string) {\n\tidx := args.IndexOfParam(checkoutURL)\n\targs.RemoveParam(idx)\n\targs.InsertParam(idx, replacement...)\n}\n","sourceCodeStart":138,"sourceCodeEnd":167,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/checkout.go#L138-L167","documentation":"Same guard as the -b case: sanitizeCheckoutFlags rejects `--orphan` because creating an orphan (history-less) branch is incompatible with how hub checks out a pull request's head ref into a new local branch. The error is returned before any git command runs.","triggerScenarios":"Running `hub checkout <pr-url> --orphan` — passing git-checkout's --orphan flag alongside a pull-request checkout.","commonSituations":"Scripts templating `git checkout --orphan` conversions onto the hub PR form; users wanting to start a fresh branch from a PR without history — an inherently conflicting request.","solutions":["Remove --orphan; check out the PR normally with `hub checkout <pr-url>`.","If you truly need an orphan branch, run it separately: `git checkout --orphan newbranch` after checking out the PR.","Use raw git plumbing: git fetch origin pull/<n>/head, then git checkout --orphan mybranch and git reset --hard FETCH_HEAD."],"exampleFix":"// before\nhub checkout https://github.com/owner/repo/pull/42 --orphan\n// after\nhub checkout https://github.com/owner/repo/pull/42\ngit checkout --orphan fresh-start","handlingStrategy":"validation","validationCode":"case \" $extra_args \" in\n  *\" --orphan \"*) echo \"--orphan is unsupported with hub PR checkout\"; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never combine --orphan with hub checkout of a PR URL.","Create orphan branches with plain git checkout --orphan in a separate step.","Sanitize forwarded arguments in wrapper scripts."],"tags":["cli","git-checkout","flags"],"backgroundTag":"unsupported-flag","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}