gitbutlerapp/gitbutler · error

Failed to find remote branch's corresponding remote

Error message

Failed to find remote branch's corresponding remote

What it means

Raised in `ref_info::for_ui` (crates/but-workspace/src/ui/ref_info.rs:71) after confirming a ref is a remote-tracking branch: `extract_remote_name_and_short_name` failed to match the ref's prefix against any of the repository's known remotes. It is wrapped with context naming the unmatched remote reference.

Solutions

  1. Run `git remote -v` and confirm the remote in the ref name exists; re-add it if removed
  2. Delete stale tracking refs: `git remote prune <remote>` or `git branch -dr <name>`
  3. Fix the fetch refspec in `.git/config` if it maps branches under an unknown remote name
  4. In code, validate `remote_names` includes the ref's remote segment before calling `for_ui`

Example fix

// before
let info = RefInfo::for_ui(&repo, ref_name)?; // panics on stale remote
// after
let remotes = repo.remotes()?;
if !remotes.iter().any(|r| ref_name.starts_with(&format!("refs/remotes/{r}/"))) {
    repo.remote_delete(stale_remote)?;
}
let info = RefInfo::for_ui(&repo, ref_name)?;
Defensive patterns

Strategy: validation

Validate before calling

let remotes: Vec<String> = repo.remotes()?.iter().map(|r| r.to_string()).collect();
let remote_ok = remotes.iter().any(|r| ref_name.as_bstr().starts_with(format!("refs/remotes/{r}/").as_bytes()));
if !remote_ok { prune_stale_tracking_refs(&mut repo)?; }

Try / catch

match RefInfo::for_ui(&repo, ref_name) {
    Err(e) if e.to_string().contains("couldn't be matched with any known remote") => prune_and_retry(ref_name),
    other => other?,
}

Prevention

When it happens

Trigger: Building UI ref info for a remote-tracking ref like `refs/remotes/<remote>/...` where `<remote>` is not in the repo's configured remote names — e.g. a stale tracking ref left after the remote was removed or renamed.

Common situations: Renaming or deleting a git remote while tracking branches remain; cloning with unusual fetch refspecs; manually created refs under refs/remotes that don't correspond to a configured remote.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/dd8ba04f76c0dffc. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/ui/ref_info.rs:71

#[cfg(feature = "export-schema")]
but_schemars::register_sdk_type!(RemoteTrackingReference);

impl RemoteTrackingReference {
    /// Create a new instance from `ref_name` and `remote_names`, essentially splitting the remote
    /// name off the short name.
    pub fn for_ui(
        ref_name: gix::refs::FullName,
        remote_names: &gix::remote::Names,
    ) -> anyhow::Result<Self> {
        let (category, _short_name) = ref_name.category_and_short_name().with_context(|| {
            format!("Failed to categorize presumed remote reference '{ref_name}'")
        })?;
        if category != Category::RemoteBranch {
            bail!("Expected '{ref_name}' to be a remote tracking branch, but was {category:?}");
        }
        let (longest_remote, short_name) =
            extract_remote_name_and_short_name(ref_name.as_ref(), remote_names)
                .ok_or(anyhow::anyhow!(
                    "Failed to find remote branch's corresponding remote"
                ))
                .with_context(|| {
                    format!(
                        "Remote reference '{ref_name}' couldn't be matched with any known remote"
                    )
                })?;

        Ok(RemoteTrackingReference {
            display_name: short_name.to_str_lossy().into_owned(),
            remote_name: longest_remote,
            full_name_bytes: ref_name.into_inner(),
        })
    }
}

/// Information about the target reference, the one we want to integrate with.
#[derive(serde::Serialize, Debug, Clone)]

View on GitHub (pinned to 58e5313667)