{"record":{"id":"27746a495dff2c92","repo":"nikivdev/code","slug":"queued-commit-was-created-on-branch-but-current","errorCode":null,"errorMessage":"Queued commit was created on branch {} but current branch is {}. Checkout the branch or re-run with --force.","messagePattern":"Queued commit was created on branch (.+?) but current branch is (.+?)\\. Checkout the branch or re-run with --force\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":9308,"sourceCode":"                    short_sha(&entry.commit_sha),\n                    short_sha(&entry.commit_sha)\n                );\n            }\n\n            let head_sha = git_capture_in(&repo_root, &[\"rev-parse\", \"HEAD\"])?;\n            let head_sha = head_sha.trim();\n            if head_sha != entry.commit_sha && !force {\n                bail!(\n                    \"Queued commit {} is not at HEAD (current HEAD is {}). Checkout the commit or re-run with --force.\",\n                    short_sha(&entry.commit_sha),\n                    short_sha(head_sha)\n                );\n            }\n\n            let current_branch = git_capture_in(&repo_root, &[\"rev-parse\", \"--abbrev-ref\", \"HEAD\"])\n                .unwrap_or_else(|_| \"unknown\".to_string());\n            if current_branch.trim() != entry.branch && !force {\n                bail!(\n                    \"Queued commit was created on branch {} but current branch is {}. Checkout the branch or re-run with --force.\",\n                    entry.branch,\n                    current_branch.trim()\n                );\n            }\n\n            ensure_safe_upstream_for_commit_queue_push(&repo_root, head_sha, force)?;\n\n            if git_try_in(&repo_root, &[\"fetch\", \"--quiet\"]).is_ok() {\n                if let Ok(counts) = git_capture_in(\n                    &repo_root,\n                    &[\"rev-list\", \"--left-right\", \"--count\", \"@{u}...HEAD\"],\n                ) {\n                    let parts: Vec<&str> = counts.split_whitespace().collect();\n                    if parts.len() == 2 {\n                        let behind = parts[0].parse::<u64>().unwrap_or(0);\n                        if behind > 0 && !force {\n                            bail!(","sourceCodeStart":9290,"sourceCodeEnd":9326,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L9290-L9326","documentation":"The queue entry records the branch on which the commit was created (`entry.branch`). At approval time the library resolves the current branch via `git rev-parse --abbrev-ref HEAD` and, unless `--force` is given, refuses to proceed when they differ. This prevents pushing/approving a commit from the wrong checked-out branch. If the branch cannot be resolved it falls back to \"unknown\", which also triggers the mismatch.","triggerScenarios":"Executing the approve/push command while a different branch than the one the queued commit was made on is checked out; detached HEAD resolves to \"unknown\"; branch was renamed or switched after queueing; `--force` omitted.","commonSituations":"Developer queues on feature/x, switches to main or another feature branch, then runs approval; detached-HEAD state during a bisect; branch renamed locally after queueing.","solutions":["`git checkout <entry.branch>` to switch back to the branch the commit was created on, then re-run.","Confirm the intended branch with `git branch --show-current` before approving.","Re-run with `--force` if approving from a different branch is intentional.","Re-create/queue the commit on the correct branch."],"exampleFix":"// before\nf pr approve            # on main, queued on feature/x\n// after\ngit checkout feature/x\nf pr approve            # or: f pr approve --force","handlingStrategy":"validation","validationCode":"let branch = String::from_utf8(Command::new(\"git\").args([\"rev-parse\",\"--abbrev-ref\",\"HEAD\"]).output().unwrap().stdout).unwrap();\nif branch.trim() != queued_branch { eprintln!(\"Switch to {} before approving\", queued_branch); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = run() {\n    if e.to_string().contains(\"was created on branch\") { eprintln!(\"git checkout <queued-branch> first\"); }\n    else { return Err(e.into()); }\n}","preventionTips":["Stay on the queueing branch until approval completes.","Avoid detached-HEAD work (bisect/debug) while a commit is queued.","Confirm with `git branch --show-current` before approving.","Rename branches only after clearing the queue."],"tags":["git","cli","branch-mismatch"],"backgroundTag":"wrong-branch-checkout","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}