{"record":{"id":"296e4f736086631e","repo":"gitbutlerapp/gitbutler","slug":"no-default-target-branch-set","errorCode":null,"errorMessage":"No default target branch set.","messagePattern":"No default target branch set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":566,"sourceCode":"    let head_name = head\n        .referent_name()\n        .map(|n| n.shorten().to_owned())\n        .unwrap_or_default();\n    if !head_name.starts_with(b\"gitbutler/\") {\n        anyhow::bail!(\"Not currently on a gitbutler/* branch.\");\n    }\n\n    // When on gitbutler/edit, the project was already set up when entering edit mode.\n    // The workspace graph built from gitbutler/edit doesn't expose the target ref or\n    // remote configuration, but both are still configured in virtual_branches.toml\n    // and will be accessible when returning to gitbutler/workspace.\n    if head_name == b\"gitbutler/edit\" {\n        return Ok(true);\n    }\n\n    // TODO(legacy): it's fine to have no target.\n    if ws.graph.project_meta.target_ref.is_none() {\n        anyhow::bail!(\"No default target branch set.\");\n    }\n\n    // check if there is a remote\n    if ws.push_remote_name().is_none()\n        && repo\n            .remote_default_name(gix::remote::Direction::Push)\n            .is_none()\n    {\n        anyhow::bail!(\n            \"Neither found push remote found in workspace nor unambiguously in the Git repository configuration.\"\n        )\n    };\n\n    Ok(true)\n}\n\n/// Creates a 'gb-local' remote pointing to this repository and creates tracking refs for the default branch.\nfn setup_local_remote(repo: &gix::Repository, out: &mut OutputChannel) -> anyhow::Result<String> {","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/setup.rs#L548-L584","documentation":"After confirming HEAD is a `gitbutler/*` branch (and not `gitbutler/edit`), `check_project_setup` requires the workspace's project metadata to define a target ref in `virtual_branches.toml`. A workspace with no target branch has nothing to diff/apply against, so setup refuses to continue.","triggerScenarios":"Calling `init_ctx` while on a `gitbutler/*` branch (other than `gitbutler/edit`) when `ws.graph.project_meta.target_ref` is `None` — e.g. `virtual_branches.toml` lost or never recorded its target, or the workspace was created without choosing a base branch.","commonSituations":"Hand-edited or corrupted `virtual_branches.toml` (`.git/gitbutler/virtual_branches.toml`); upgrading from an old GitButler version whose metadata format lacked the target; a partially initialized workspace.","solutions":["Re-select the target/base branch for the project (via the GitButler app or the command that sets the default target) so `virtual_branches.toml` gains a `target_ref`.","Check `.git/gitbutler/virtual_branches.toml` and restore/repair the `[target]` entry (or delete it and let setup re-create it).","Ensure you are not on `gitbutler/edit` incorrectly expecting workspace metadata; move to `gitbutler/workspace` where the target is configured."],"exampleFix":"// before: virtual_branches.toml missing target\n[target]\n// after: target restored\n[target]\nsha = \"abc123...\"\nbranch = \"refs/remotes/origin/main\"","handlingStrategy":"validation","validationCode":"let vbt = \".git/gitbutler/virtual_branches.toml\";\nlet ok = std::fs::read_to_string(vbt)\n    .map(|c| c.contains(\"[target]\"))\n    .unwrap_or(false);\nif !ok {\n    eprintln!(\"workspace has no target branch; re-select the base branch first\");\n    std::process::exit(1);\n}","typeGuard":"fn has_target_ref(meta: &ProjectMeta) -> bool {\n    meta.target_ref.is_some()\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"No default target branch set\") => {\n        // run the target-selection flow, then retry\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Never hand-edit `virtual_branches.toml` without keeping the `[target]` section","Re-select the target branch after restoring `.git/gitbutler/` from backup","Prefer `gitbutler/edit`/`workspace` states where metadata is intact"],"tags":["git","config","workspace","missing-config"],"backgroundTag":"missing-required-config-field","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"}