{"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":null,"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/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/setup.rs#L134-L170","documentation":"During context initialization (`init_ctx`), if no target branch is configured for the project, the CLI attempts to infer a default target via but_workspace::init::infer_default_target_ref. When inference also returns None, this error tells the user to configure a target explicitly with `but config target`.","triggerScenarios":"Running a `but` command on a project with no stored target ref and no remote-tracking branch that can serve as an inferred default (e.g., repository with no remotes or no fetched remote branches).","commonSituations":"Freshly initialized repo without any remote; remote added but never fetched (no origin/main ref locally); target config removed or corrupted; bare clone without remote tracking refs.","solutions":["Run `but config target <remote>/<branch>`, e.g. `but config target origin/main`.","If no remote exists yet, add one with `git remote add origin <url>` and `git fetch origin`, then retry.","Verify the remote-tracking branch exists locally: `git branch -r`."],"exampleFix":"// before\n$ but status\nError: No target branch is configured...\n// after\n$ git fetch origin\n$ but config target origin/main\n$ but status","handlingStrategy":"validation","validationCode":"if !git.branchExists('origin/main') { die('run: but config target origin/main (after git fetch)'); }","typeGuard":null,"tryCatchPattern":"match ctx.init() {\n  Err(e) if e.to_string().contains(\"No target branch is configured\") => {\n    eprintln!(\"Run: but config target <remote>/<branch>\");\n  }\n  other => other?,\n}","preventionTips":["Always fetch remotes after cloning before first `but` use.","Configure the target explicitly on new projects.","Verify `git branch -r` output is non-empty."],"tags":["cli","git","configuration","target-branch"],"backgroundTag":"missing-required-config","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"}