{"record":{"id":"ea9debd16d15d5da","repo":"gitbutlerapp/gitbutler","slug":"couldn-t-find-remote-refspecs-that-would-match-br","errorCode":null,"errorMessage":"Couldn't find remote refspecs that would match {branch}","messagePattern":"Couldn't find remote refspecs that would match (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/apply.rs","lineNumber":264,"sourceCode":"    let new_stack_id = new_stack_id.unwrap_or(generate_new_stack_id);\n    let branch_orig = branch;\n    let (mut branch_ref, mut incoming_branch_is_remote_tracking_without_local_tracking) =\n        (try_find_validated_ref(repo, branch, \"apply\")?, false);\n    if ws.is_branch_the_target_or_its_local_tracking_branch(branch) {\n        bail!(\"Cannot add the target '{branch}' branch to its own workspace\");\n    }\n    let mut branch = branch.to_owned();\n    if branch\n        .category()\n        .is_some_and(|c| c == Category::RemoteBranch)\n    {\n        // TODO(gix): we really want to have a function to return the local tracking branch\n        //            fix this in other places, too.\n        let Some((upstream_branch_name, _remote_name)) =\n            repo.upstream_branch_and_remote_for_tracking_branch(branch.as_ref())?\n        else {\n            // TODO: actually create a local trakcing branch with proper configuration.\n            bail!(\"Couldn't find remote refspecs that would match {branch}\");\n        };\n        // Pretend the upstream branch is also the local tracking name.\n        incoming_branch_is_remote_tracking_without_local_tracking = true;\n        branch = upstream_branch_name;\n        branch_ref = try_find_validated_ref(repo, branch.as_ref(), \"apply\")?;\n    }\n    let head_ref_name = repo.head_name()?.map(|name| name.to_owned());\n    let head_on_managed_workspace_ref = match &ws.kind {\n        WorkspaceKind::Managed { ref_info }\n        | WorkspaceKind::ManagedMissingWorkspaceCommit { ref_info } => head_ref_name\n            .as_ref()\n            .is_some_and(|head| head == &ref_info.ref_name),\n        WorkspaceKind::AdHoc => false,\n    };\n    let branch_has_applied_metadata =\n        branch_has_applied_workspace_metadata(branch.as_ref(), &ws, meta)?;\n    let branch_already_applied = (ws.ref_name() == Some(branch.as_ref())\n        || ws.refname_is_segment(branch.as_ref()))","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/apply.rs#L246-L282","documentation":"When `apply` receives a remote-tracking branch (a branch in the `Category::RemoteBranch` category) it looks up the corresponding upstream configuration to derive the local tracking branch name. If git reports no upstream/refspec mapping for that branch (`upstream_branch_and_remote_for_tracking_branch` returns `None`), the tool cannot map the remote branch to a local one and bails.","triggerScenarios":"Calling `apply` with a remote branch like `origin/feature-x` whose local branch has no upstream configuration, or when no remote refspec (e.g. `+refs/heads/*:refs/remotes/origin/*`) matches the branch.","commonSituations":"Fresh clones with missing `branch.<name>.remote`/`merge` config; manually deleted local tracking branches; remotes configured with narrow fetch refspecs that exclude the branch.","solutions":["Create or fix the local branch and set its upstream: `git branch feature-x origin/feature-x` (or `git branch --set-upstream-to=origin/feature-x feature-x`).","Ensure the remote's fetch refspec covers the branch: `git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'`.","Apply the local tracking branch instead of the remote-tracking name."],"exampleFix":"// before\nws.branch_apply(repo, \"origin/feature-x\", ...).await?;\n// after\nws.branch_apply(repo, \"feature-x\", ...).await?; // local tracking branch","handlingStrategy":"validation","validationCode":"if branch.starts_with(\"origin/\") {\n    let local = &branch[\"origin/\".len()..];\n    assert!(repo.try_find_reference(&local)?.is_some(), \"no local tracking branch for {branch}\");\n}","typeGuard":null,"tryCatchPattern":"// Rust\nif let Err(e) = ws.branch_apply(repo, branch, ...).await {\n    if e.to_string().starts_with(\"Couldn't find remote refspecs\") {\n        eprintln!(\"set upstream for the branch first: git branch --set-upstream-to=...\");\n        return Err(e);\n    }\n    return Err(e);\n}","preventionTips":["Prefer applying local branches over remote-tracking names.","Keep the standard fetch refspec `+refs/heads/*:refs/remotes/origin/*` on remotes.","After cloning, verify `git branch -vv` shows upstreams before automated applies."],"tags":["git","workspace","remote","refspec"],"backgroundTag":"resource-not-found","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"}