{"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":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":516,"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.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":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/command/legacy/setup.rs#L498-L534","documentation":"check_project_setup (crates/but/src/command/legacy/setup.rs:516) bails when the loaded workspace graph has no default target branch (ws.graph.project_meta.target_ref is None). The target ref is persisted in .git/gitbutler/virtual_branches.toml; without it GitButler cannot compute the workspace base. The code's TODO marks no-target as expected to become acceptable, but today it is a hard setup failure.","triggerScenarios":"Running setup-checked commands when virtual_branches.toml is missing, empty, or lacks the default target entry: interrupted first-run setup, hand-edited or corrupted config, or config loss after repo moves.","commonSituations":"Setup was aborted between creating the workspace branch and writing the target; virtual_branches.toml deleted or truncated; repo copied without .git/gitbutler; downgrade/upgrade wrote a config the current reader cannot map to target_ref.","solutions":["Run `but setup` (or app onboarding) to re-select the default target branch, which rewrites default.target in virtual_branches.toml.","Inspect .git/gitbutler/virtual_branches.toml and verify the [default] section contains a target ref entry.","If the file is corrupted, remove it and re-run setup to regenerate it; branches already pushed remain recoverable from remote refs."],"exampleFix":"# .git/gitbutler/virtual_branches.toml before\n[default]\nremote = \"origin\"\n\n# after\n[default]\nremote = \"origin\"\ntarget = \"refs/heads/main\"","handlingStrategy":"validation","validationCode":"let (repo, ws, _) = ctx.workspace_and_db_with_perm(perm)?;\nif ws.graph.project_meta.target_ref.is_none() {\n    // run setup / rewrite virtual_branches.toml [default] target before continuing\n}","typeGuard":null,"tryCatchPattern":"if let Err(err) = check_project_setup(&ctx, &perm) {\n    if err.to_string().contains(\"No default target branch\") {\n        // re-run `but setup` to repopulate the target, then retry once\n    }\n}","preventionTips":["Keep .git/gitbutler/virtual_branches.toml under review when hand-editing gitbutler state.","Complete onboarding (setup) fully; do not interrupt first-run initialization.","After moving or cloning repos, re-run setup if GitButler commands fail."],"tags":["gitbutler","config","target-branch","toml","setup"],"backgroundTag":"missing-default-branch-config","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}