{"record":{"id":"0219fbe4a58c3e02","repo":"gitbutlerapp/gitbutler","slug":"no-target-branch-is-configured-and-none-could-be-i","errorCode":null,"errorMessage":"No target branch is configured and none could be inferred. Run `but config target <remote>/<branch>` to configure one.","messagePattern":"No target branch is configured and none could be inferred\\. Run `but config target <remote>/<branch>` to configure one\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but/src/setup.rs","lineNumber":152,"sourceCode":"                let project = match LegacyProject::find_by_worktree_dir(workdir) {\n                    Ok(project) => project,\n                    Err(_) => match gitbutler_project::add(workdir)? {\n                        gitbutler_project::AddProjectOutcome::Added(project)\n                        | gitbutler_project::AddProjectOutcome::AlreadyExists(project) => project,\n                        outcome => outcome.try_project()?,\n                    },\n                };\n                let mut ctx =\n                    Context::new_from_legacy_project_and_settings(&project, app_settings.clone())?;\n                if matches!(options.target_requirement, TargetRequirement::Required)\n                    && ctx.project_meta()?.target_ref.is_none()\n                {\n                    let target_ref = {\n                        let repo = ctx.repo.get()?;\n                        but_workspace::init::infer_default_target_ref(&repo)?\n                    }\n                    .ok_or_else(|| {\n                        anyhow::anyhow!(\n                            \"No target branch is configured and none could be inferred. Run `but config target <remote>/<branch>` to configure one.\"\n                        )\n                    })?;\n                    but_api::workspace::set_target_ref_and_init_project(\n                        &mut ctx,\n                        target_ref.as_ref(),\n                        None,\n                    )?;\n                }\n\n                let fetch_interval_minutes = ctx.settings.fetch.auto_fetch_interval_minutes;\n                let last_fetch = ctx\n                    .legacy_project\n                    .project_data_last_fetch\n                    .as_ref()\n                    .map(|f| f.timestamp());\n                (ctx, fetch_interval_minutes, last_fetch)\n            } else {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/setup.rs#L134-L170","documentation":"Several but commands require the project to have a target (base) branch. If the project has no target_ref configured and but_workspace::init::infer_default_target_ref cannot find a candidate (typically no remotes, or no recognizable default branch), setup stops and tells you to configure one explicitly.","triggerScenarios":"Running a command with TargetRequirement::Required (setup / workspace init) in a repo with no remotes at all, or with remotes but no origin/HEAD and no main/master remote branch to pick.","commonSituations":"Freshly `git init`-ed local-only repos; forks whose default remote branch is uncommon (e.g. develop) with the remote HEAD unset.","solutions":["Configure it explicitly as the message says: `but config target origin/main`","Give inference something to find: `git remote add origin <url> && git fetch origin`, then retry","Set the remote HEAD so inference succeeds: `git remote set-head origin --auto`"],"exampleFix":"# before\nbut setup    # no target_ref and inference finds nothing\n# after\nbut config target origin/main\nbut setup","handlingStrategy":"validation","validationCode":"let has_remote_head = std::process::Command::new(\"git\")\n    .args([\"symbolic-ref\", \"-q\", \"refs/remotes/origin/HEAD\"])\n    .output()?;\nif !has_remote_head.status.success() {\n    // no inferable default: set target explicitly before running setup\n}","typeGuard":null,"tryCatchPattern":"Catch this error in automation and fall back to running `but config target <remote>/<branch>` before retrying setup.","preventionTips":["Fetch and set the remote HEAD right after cloning (git remote set-head origin --auto)","Script `but config target <remote>/<branch>` as part of onboarding"],"tags":["target-branch","setup","workspace","configuration"],"backgroundTag":"missing-default-branch-config","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}