gitbutlerapp/gitbutler · error
No target branch is configured and none could be inferred…
Error message
No target branch is configured and none could be inferred. Run `but config target <remote>/<branch>` to configure one.
What it means
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`.
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`.
Example fix
// before $ but status Error: No target branch is configured... // after $ git fetch origin $ but config target origin/main $ but status
Defensive patterns
Strategy: validation
Validate before calling
if !git.branchExists('origin/main') { die('run: but config target origin/main (after git fetch)'); } Try / catch
match ctx.init() {
Err(e) if e.to_string().contains("No target branch is configured") => {
eprintln!("Run: but config target <remote>/<branch>");
}
other => other?,
} Prevention
- Always fetch remotes after cloning before first `but` use.
- Configure the target explicitly on new projects.
- Verify `git branch -r` output is non-empty.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- DefaultTargetNotFound
- Local AI configuration requires running inside a git…
- Aborting due to empty branch name
- Bare repositories are not supported.
- Branch ' ' not found
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/0219fbe4a58c3e02.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/setup.rs:152
let project = match LegacyProject::find_by_worktree_dir(workdir) {
Ok(project) => project,
Err(_) => match gitbutler_project::add(workdir)? {
gitbutler_project::AddProjectOutcome::Added(project)
| gitbutler_project::AddProjectOutcome::AlreadyExists(project) => project,
outcome => outcome.try_project()?,
},
};
let mut ctx =
Context::new_from_legacy_project_and_settings(&project, app_settings.clone())?;
if matches!(options.target_requirement, TargetRequirement::Required)
&& ctx.project_meta()?.target_ref.is_none()
{
let target_ref = {
let repo = ctx.repo.get()?;
but_workspace::init::infer_default_target_ref(&repo)?
}
.ok_or_else(|| {
anyhow::anyhow!(
"No target branch is configured and none could be inferred. Run `but config target <remote>/<branch>` to configure one."
)
})?;
but_api::workspace::set_target_ref_and_init_project(
&mut ctx,
target_ref.as_ref(),
None,
)?;
}
let fetch_interval_minutes = ctx.settings.fetch.auto_fetch_interval_minutes;
let last_fetch = ctx
.legacy_project
.project_data_last_fetch
.as_ref()
.map(|f| f.timestamp());
(ctx, fetch_interval_minutes, last_fetch)
} else {View on GitHub (pinned to 58e5313667)