gitbutlerapp/gitbutler · error

failed to determine remote and branch name for

Error message

failed to determine remote and branch name for `{branch}`

What it means

remote_tracking_branch_parts splits a fully-qualified branch ref into (remote, short branch name) using extract_remote_name_and_short_name against the repo's registered remotes. When the ref does not start with any registered remote name followed by `/`, the split fails and this error is thrown.

Solutions

  1. Register the missing remote (`git remote add <name> <url>`) so the ref prefix resolves.
  2. Confirm the ref name format is `refs/remotes/<registered-remote>/<branch>`.
  3. Remove or ignore stale tracking refs from unregistered remotes.
  4. If remote names create ambiguity, rename the remote (`git remote rename`).

Example fix

// before: ref refs/remotes/upstream/feature, only 'origin' registered
git remote add upstream <url>
// after: remote_tracking_branch_parts resolves ("upstream", "feature")
Defensive patterns

Strategy: validation

Validate before calling

let remotes: Vec<_> = repo.remote_names().iter().map(|b| b.to_string()).collect();
let short = branch.as_bstr().strip_prefix(b"refs/remotes/");
if !short.map_or(false, |s| remotes.iter().any(|r| s.starts_with(r.as_bytes())) ) {
    return Err(anyhow!("ref {} does not match any registered remote", branch));
}

Prevention

When it happens

Trigger: Calling push_with_askpass (or the helper directly) with a branch FullNameRef whose prefix matches no configured remote — e.g. `refs/remotes/upstream/x` when only `origin` is registered, or a remote name ambiguous with slashes/unregistered entries.

Common situations: Multiple remotes where one was removed from config; tracking refs from a remote not registered locally (fetched via URL); ambiguity when one remote name is a prefix of another path segment.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at crates/gitbutler-git/src/context.rs:322

) -> std::result::Result<S::Ok, S::Error>
where
    S: serde::Serializer,
{
    branch_to_remote
        .iter()
        .map(|(branch_name, refname, remote_branch_name)| {
            (branch_name, refname.to_string(), remote_branch_name)
        })
        .collect::<Vec<_>>()
        .serialize(serializer)
}

fn remote_tracking_branch_parts(
    repo: &gix::Repository,
    branch: &gix::refs::FullNameRef,
) -> Result<(String, String)> {
    let (remote, short_name) = extract_remote_name_and_short_name(branch, &repo.remote_names())
        .ok_or_else(|| anyhow!("failed to determine remote and branch name for `{branch}`"))?;
    let short_name = std::str::from_utf8(short_name.as_ref())
        .context(format!("branch name for `{branch}` is not valid UTF-8"))?
        .to_owned();
    Ok((remote, short_name))
}

fn now_ms() -> u128 {
    UNIX_EPOCH
        .elapsed()
        .expect("system time is set before the Unix epoch")
        .as_millis()
}

async fn handle_git_prompt_push(
    prompt: String,
    askpass: Option<Option<StackId>>,
) -> Option<String> {
    if let Some(branch_id) = askpass {

View on GitHub (pinned to 58e5313667)