{"record":{"id":"0b1709e763e5de83","repo":"mislav/hub","slug":"unsupported-flag-b-when-checking-out-pull-request","errorCode":null,"errorMessage":"Unsupported flag -b when checking out pull request","messagePattern":"Unsupported flag -b when checking out pull request","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/checkout.go","lineNumber":152,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\n\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":134,"sourceCodeEnd":167,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/checkout.go#L134-L167","documentation":"When `hub checkout <pull-request-url>` runs, sanitizeCheckoutFlags scans the user's extra git arguments and rejects flags that conflict with hub's pull-request checkout behavior. `-b` (create a new branch) is rejected because hub already creates its own branch named after the PR, so passing -b is unsupported.","triggerScenarios":"Running `hub checkout <pr-url-or-number> -b <branch>` — i.e. appending git-checkout's -b flag to a hub PR checkout command.","commonSituations":"Muscle memory from `git checkout -b feature` applied to the hub PR checkout form; scripting that blindly forwards extra args to git checkout; users wanting a custom branch name for the PR.","solutions":["Drop the -b flag: `hub checkout <pr-url>` already creates a local branch for the PR.","Rename the branch afterwards with `git branch -m` if you want a custom name.","Use plain `git fetch origin pull/<n>/head && git checkout -b myname FETCH_HEAD` if you need full control over the branch creation."],"exampleFix":"// before\nhub checkout https://github.com/owner/repo/pull/42 -b my-feature\n// after\nhub checkout https://github.com/owner/repo/pull/42\ngit branch -m my-feature","handlingStrategy":"validation","validationCode":"// Strip -b/--orphan before invoking hub checkout for a PR:\nargs := filtered(args, func(a string) bool { return a != \"-b\" && a != \"--orphan\" })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember hub checkout creates the PR branch for you; never pass -b.","In scripts that forward args to hub checkout, filter git-only flags first.","Rename branches post-checkout with git branch -m instead of -b."],"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"}