gitbutlerapp/gitbutler · error

failed to determine remote for non remote-tracking branch

Error message

failed to determine remote for non remote-tracking branch {target_ref}

What it means

push_remote_name derives the remote name for a stack's target ref. If the ref is not a remote-tracking branch (refs/remotes/<remote>/<short>), it cannot yield a remote and bails. The ref must parse via category_and_short_name() and be Category::RemoteBranch.

Solutions

  1. Ensure the stack's target ref is a remote-tracking branch (refs/remotes/<remote>/<branch>) before deriving the push remote
  2. Set an upstream for the local branch (git push -u <remote> <branch>) and use that ref
  3. Fall back to a configured default remote when the target ref is local

Example fix

// before
let remote = metadata.push_remote_name(repo)?;
// after
let remote = match metadata.target_ref_is_remote_tracking() {
    true => metadata.push_remote_name(repo)?,
    false => repo.find_default_remote_name().unwrap_or_else(|| bail!("no upstream or default remote")),
};
Defensive patterns

Strategy: fallback

Validate before calling

let is_remote_tracking = target_ref.category_and_short_name()
    .map(|(c, _)| c == gix::refs::Category::RemoteBranch)
    .unwrap_or(false);

Try / catch

let remote = push_remote_name(repo).ok().or_else(|| repo_remote_default(repo));

Prevention

When it happens

Trigger: Calling push_remote_name (via ref_metadata remote lookups) when target_ref is a local branch, a tag, or another non-remote-tracking category; or a remote-tracking branch whose short name contains no '/' (no remote segment).

Common situations: Stacks created from a purely local branch with no upstream; corrupted or hand-edited refs; refs like refs/remotes/main without a remote component.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-core/src/ref_metadata.rs:333

    /// remote behind [`Self::target_ref`].
    ///
    /// If no configured remote matches the target ref, fall back to the first path component
    /// after `refs/remotes/`, the textual remote name that legacy metadata stored verbatim.
    pub fn push_remote_name(&self, repo: &gix::Repository) -> Result<String> {
        if let Some(name) = self.push_remote.clone() {
            return Ok(name);
        }
        let target_ref = self.target_ref_or_err()?;
        if let Some((remote_name, _short_name)) =
            extract_remote_name_and_short_name(target_ref.as_ref(), &repo.remote_names())
        {
            return Ok(remote_name);
        }
        let (category, short_name) = target_ref
            .category_and_short_name()
            .with_context(|| format!("failed to determine remote for branch {target_ref}"))?;
        if category != gix::refs::Category::RemoteBranch {
            bail!("failed to determine remote for non remote-tracking branch {target_ref}");
        }
        let slash_pos = short_name.find_byte(b'/').with_context(|| {
            format!("remote tracking branch {target_ref} didn't have '/' in its short name")
        })?;
        let remote_name = short_name[..slash_pos].to_str_lossy().into_owned();
        tracing::warn!(
            "remote '{remote_name}' of target ref {target_ref} is not configured in git config"
        );
        Ok(remote_name)
    }

    /// Get the fetch URL of the remote behind [`Self::target_ref`].
    pub fn remote_url_with_fallback(&self, repo: &gix::Repository) -> Result<String> {
        let Some(target_ref) = self.target_ref.as_ref() else {
            bail!("Target ref required for remote url")
        };
        let remote_names = repo.remote_names();
        let (remote_name, _short_name) =

View on GitHub (pinned to 58e5313667)