gitbutlerapp/gitbutler · error · anyhow::Error
No target branch is configured and none could be inferred. R
Error message
No target branch is configured and none could be inferred. Run `but config target <remote>/<branch>` to configure one.
What it means
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.
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 caf1f223d3)
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`
Example fix
# before but setup # no target_ref and inference finds nothing # after but config target origin/main but setup
Defensive patterns
Strategy: validation
Validate before calling
let has_remote_head = std::process::Command::new("git")
.args(["symbolic-ref", "-q", "refs/remotes/origin/HEAD"])
.output()?;
if !has_remote_head.status.success() {
// no inferable default: set target explicitly before running setup
} Try / catch
Catch this error in automation and fall back to running `but config target <remote>/<branch>` before retrying setup.
Prevention
- 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
When it happens
Trigger: 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.
Common situations: Freshly `git init`-ed local-only repos; forks whose default remote branch is uncommon (e.g. develop) with the remote HEAD unset.
Related errors
- DefaultTargetNotFound
- No base branch configured
- No default target branch set.
- Failed to determine Gerrit target branch
- When using OpenRouter, you must provide a valid API key
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/0219fbe4a58c3e02.
Report an issue: GitHub.