nikivdev/code · error
Queued commit was created on branch {} but current branch is
Error message
Queued commit was created on branch {} but current branch is {}. Checkout the branch or re-run with --force. What it means
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.
Source
Thrown at src/commit.rs:9308
short_sha(&entry.commit_sha),
short_sha(&entry.commit_sha)
);
}
let head_sha = git_capture_in(&repo_root, &["rev-parse", "HEAD"])?;
let head_sha = head_sha.trim();
if head_sha != entry.commit_sha && !force {
bail!(
"Queued commit {} is not at HEAD (current HEAD is {}). Checkout the commit or re-run with --force.",
short_sha(&entry.commit_sha),
short_sha(head_sha)
);
}
let current_branch = git_capture_in(&repo_root, &["rev-parse", "--abbrev-ref", "HEAD"])
.unwrap_or_else(|_| "unknown".to_string());
if current_branch.trim() != entry.branch && !force {
bail!(
"Queued commit was created on branch {} but current branch is {}. Checkout the branch or re-run with --force.",
entry.branch,
current_branch.trim()
);
}
ensure_safe_upstream_for_commit_queue_push(&repo_root, head_sha, force)?;
if git_try_in(&repo_root, &["fetch", "--quiet"]).is_ok() {
if let Ok(counts) = git_capture_in(
&repo_root,
&["rev-list", "--left-right", "--count", "@{u}...HEAD"],
) {
let parts: Vec<&str> = counts.split_whitespace().collect();
if parts.len() == 2 {
let behind = parts[0].parse::<u64>().unwrap_or(0);
if behind > 0 && !force {
bail!(View on GitHub (pinned to a747e741ae)
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.
Example fix
// before f pr approve # on main, queued on feature/x // after git checkout feature/x f pr approve # or: f pr approve --force
Defensive patterns
Strategy: validation
Validate before calling
let branch = String::from_utf8(Command::new("git").args(["rev-parse","--abbrev-ref","HEAD"]).output().unwrap().stdout).unwrap();
if branch.trim() != queued_branch { eprintln!("Switch to {} before approving", queued_branch); } Try / catch
if let Err(e) = run() {
if e.to_string().contains("was created on branch") { eprintln!("git checkout <queued-branch> first"); }
else { return Err(e.into()); }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Queued commit {} is not at HEAD (current HEAD is {}). Checko
- git {} failed: {}
- {} is not inside a git repository
- not inside a git repository
- git {} failed
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/27746a495dff2c92.
Report an issue: GitHub.