{"record":{"id":"02527c8a2e6c5bac","repo":"gitbutlerapp/gitbutler","slug":"failed-to-determine-remote-for-non-remote-tracking","errorCode":null,"errorMessage":"failed to determine remote for non remote-tracking branch {target_ref}","messagePattern":"failed to determine remote for non remote-tracking branch (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/ref_metadata.rs","lineNumber":333,"sourceCode":"    /// remote behind [`Self::target_ref`].\n    ///\n    /// If no configured remote matches the target ref, fall back to the first path component\n    /// after `refs/remotes/`, the textual remote name that legacy metadata stored verbatim.\n    pub fn push_remote_name(&self, repo: &gix::Repository) -> Result<String> {\n        if let Some(name) = self.push_remote.clone() {\n            return Ok(name);\n        }\n        let target_ref = self.target_ref_or_err()?;\n        if let Some((remote_name, _short_name)) =\n            extract_remote_name_and_short_name(target_ref.as_ref(), &repo.remote_names())\n        {\n            return Ok(remote_name);\n        }\n        let (category, short_name) = target_ref\n            .category_and_short_name()\n            .with_context(|| format!(\"failed to determine remote for branch {target_ref}\"))?;\n        if category != gix::refs::Category::RemoteBranch {\n            bail!(\"failed to determine remote for non remote-tracking branch {target_ref}\");\n        }\n        let slash_pos = short_name.find_byte(b'/').with_context(|| {\n            format!(\"remote tracking branch {target_ref} didn't have '/' in its short name\")\n        })?;\n        let remote_name = short_name[..slash_pos].to_str_lossy().into_owned();\n        tracing::warn!(\n            \"remote '{remote_name}' of target ref {target_ref} is not configured in git config\"\n        );\n        Ok(remote_name)\n    }\n\n    /// Get the fetch URL of the remote behind [`Self::target_ref`].\n    pub fn remote_url_with_fallback(&self, repo: &gix::Repository) -> Result<String> {\n        let Some(target_ref) = self.target_ref.as_ref() else {\n            bail!(\"Target ref required for remote url\")\n        };\n        let remote_names = repo.remote_names();\n        let (remote_name, _short_name) =","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/ref_metadata.rs#L315-L351","documentation":"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.","triggerScenarios":"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).","commonSituations":"Stacks created from a purely local branch with no upstream; corrupted or hand-edited refs; refs like refs/remotes/main without a remote component.","solutions":["Ensure the stack's target ref is a remote-tracking branch (refs/remotes/<remote>/<branch>) before deriving the push remote","Set an upstream for the local branch (git push -u <remote> <branch>) and use that ref","Fall back to a configured default remote when the target ref is local"],"exampleFix":"// before\nlet remote = metadata.push_remote_name(repo)?;\n// after\nlet remote = match metadata.target_ref_is_remote_tracking() {\n    true => metadata.push_remote_name(repo)?,\n    false => repo.find_default_remote_name().unwrap_or_else(|| bail!(\"no upstream or default remote\")),\n};","handlingStrategy":"fallback","validationCode":"let is_remote_tracking = target_ref.category_and_short_name()\n    .map(|(c, _)| c == gix::refs::Category::RemoteBranch)\n    .unwrap_or(false);","typeGuard":null,"tryCatchPattern":"let remote = push_remote_name(repo).ok().or_else(|| repo_remote_default(repo));","preventionTips":["Require an upstream/remote-tracking target for stacks that will be pushed","Handle local-only stacks with an explicit default-remote fallback","Validate ref categories early when constructing metadata"],"tags":["rust","git","refs","remote"],"backgroundTag":"incompatible-source-type","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}