nikivdev/code · error
No branches available for AI matching
Error message
No branches available for AI matching
What it means
`run_ai` (src/branches.rs:90) collects candidate branches (local or remote) and bails when the list is empty, since there is nothing for the AI to match against. Validation happens before building the prompt and calling `ai_server::quick_prompt`.
Source
Thrown at src/branches.rs:90
.first()
.map(|(_, entry)| (*entry).clone())
.context("No match available to switch")?;
println!("\nSwitching to {}...", best.name);
switch_to_entry(&best)?;
}
Ok(())
}
fn run_ai(opts: BranchAiOpts) -> Result<()> {
let query = opts.query.trim().to_string();
if query.is_empty() {
bail!("Query cannot be empty");
}
let branches = collect_branches(opts.remote)?;
if branches.is_empty() {
bail!("No branches available for AI matching");
}
let candidates = top_candidates_for_ai(&query, &branches, opts.limit.max(1));
let prompt = build_ai_prompt(&query, &candidates);
let response =
ai_server::quick_prompt(&prompt, opts.model.as_deref(), opts.url.as_deref(), None)?;
let cleaned_response = response.trim().trim_matches('`').trim();
if cleaned_response.eq_ignore_ascii_case("none") {
println!("AI selected no matching branch.");
return Ok(());
}
let selected_name = parse_ai_branch_response(&response, &candidates)
.with_context(|| format!("Could not parse AI branch response: {}", response.trim()))?;
let selected = candidates
.iter()
.find(|e| e.name == selected_name)
.cloned()View on GitHub (pinned to a747e741ae)
Solutions
- Run the command inside a repository with at least one branch
- Fetch remote refs before using --remote: `git fetch --all`
- Verify the repo state with `git branch -a`
- Omit --remote if you only intend to match local branches
Defensive patterns
Strategy: validation
Validate before calling
let out = std::process::Command::new("git").args(["branch", "--list"]).output()?;
if String::from_utf8_lossy(&out.stdout).trim().is_empty() {
anyhow::bail!("no branches in this repo; make a commit or fetch remotes first");
} Type guard
fn branches_available(b: &[Branch]) -> bool { !b.is_empty() } Try / catch
match run_ai(opts) {
Err(e) if e.to_string().contains("No branches available for AI matching") => {
eprintln!("cd into the repo and/or `git fetch --all`, then retry");
}
other => other?,
} Prevention
- Confirm the repo has commits (`git log -1`) before AI matching
- Fetch remote refs before using --remote
- Set the correct working directory in scripts and CI jobs
When it happens
Trigger: `collect_branches(opts.remote)` returns empty — command run outside a git repo, in an empty repo with no commits, or with --remote when no remote refs exist locally.
Common situations: Fresh `git init` with no commits; CI checkout with `--depth 1` and no remote refs fetched; wrong working directory in a script.
Related errors
- No branches available to search
- Commit queue is empty.
- No PR found for current branch and commit queue is empty.
- jj git export retry loop should always return
- Lin.app is not running
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/7868e4d620c82f03.
Report an issue: GitHub.