nikivdev/code · error

No branches matched query '{}'.

Error message

No branches matched query '{}'.

What it means

`run_find` (src/branches.rs:62) ranks collected branches against the query with `rank_branches` and bails when no branch scores a match. The repo has branches, but none match the search string closely enough.

Source

Thrown at src/branches.rs:62

        print_branch(entry);
    }
    Ok(())
}

fn run_find(opts: BranchFindOpts) -> 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 to search");
    }

    let ranked = rank_branches(&query, &branches);
    if ranked.is_empty() {
        bail!("No branches matched query '{}'.", query);
    }

    let limit = opts.limit.max(1);
    for (_, entry) in ranked.iter().take(limit) {
        print_branch(entry);
    }

    if opts.switch {
        let best = ranked
            .first()
            .map(|(_, entry)| (*entry).clone())
            .context("No match available to switch")?;
        println!("\nSwitching to {}...", best.name);
        switch_to_entry(&best)?;
    }

    Ok(())
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Shorten or loosen the query to a common substring of the branch name
  2. Check exact branch naming with `git branch -a`
  3. If the branch may be remote-only, retry with the --remote flag after a fetch
  4. Correct casing/separators in the query

Example fix

// before
f branch find --query "feature/add-oauth2-with-refresh-tokens"
// after
f branch find --query "oauth"
Defensive patterns

Strategy: fallback

Validate before calling

let query = opts.query.trim().to_lowercase();
if query.len() < 3 {
    anyhow::bail!("query too short to match reliably");
}

Try / catch

match run_find(opts) {
    Err(e) if e.to_string().starts_with("No branches matched") => {
        eprintln!("try a shorter substring, or `git branch -a` to list all");
    }
    other => other?,
}

Prevention

When it happens

Trigger: `f branch find --query X` where ranking of all available branches against X yields an empty result — typo, wrong naming convention, or branch deleted/renamed.

Common situations: Searching for a feature branch that was merged and deleted; name uses different casing/separators (feature/x vs feature_x); typo in the query.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/6a0ef61e078fb357. Report an issue: GitHub.