gitbutlerapp/gitbutler · error
No default target branch set.
Error message
No default target branch set.
What it means
After confirming HEAD is a `gitbutler/*` branch (and not `gitbutler/edit`), `check_project_setup` requires the workspace's project metadata to define a target ref in `virtual_branches.toml`. A workspace with no target branch has nothing to diff/apply against, so setup refuses to continue.
Solutions
- Re-select the target/base branch for the project (via the GitButler app or the command that sets the default target) so `virtual_branches.toml` gains a `target_ref`.
- Check `.git/gitbutler/virtual_branches.toml` and restore/repair the `[target]` entry (or delete it and let setup re-create it).
- Ensure you are not on `gitbutler/edit` incorrectly expecting workspace metadata; move to `gitbutler/workspace` where the target is configured.
Example fix
// before: virtual_branches.toml missing target [target] // after: target restored [target] sha = "abc123..." branch = "refs/remotes/origin/main"
Defensive patterns
Strategy: validation
Validate before calling
let vbt = ".git/gitbutler/virtual_branches.toml";
let ok = std::fs::read_to_string(vbt)
.map(|c| c.contains("[target]"))
.unwrap_or(false);
if !ok {
eprintln!("workspace has no target branch; re-select the base branch first");
std::process::exit(1);
} Type guard
fn has_target_ref(meta: &ProjectMeta) -> bool {
meta.target_ref.is_some()
} Try / catch
match result {
Err(e) if e.to_string().contains("No default target branch set") => {
// run the target-selection flow, then retry
}
Err(e) => return Err(e),
Ok(v) => v,
} Prevention
- Never hand-edit `virtual_branches.toml` without keeping the `[target]` section
- Re-select the target branch after restoring `.git/gitbutler/` from backup
- Prefer `gitbutler/edit`/`workspace` states where metadata is intact
When it happens
Trigger: Calling `init_ctx` while on a `gitbutler/*` branch (other than `gitbutler/edit`) when `ws.graph.project_meta.target_ref` is `None` — e.g. `virtual_branches.toml` lost or never recorded its target, or the workspace was created without choosing a base branch.
Common situations: Hand-edited or corrupted `virtual_branches.toml` (`.git/gitbutler/virtual_branches.toml`); upgrading from an old GitButler version whose metadata format lacked the target; a partially initialized workspace.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' cannot be created: the target commit ( ) already…
- BranchNotFound
- BUG: failed to apply head ref
- Cannot add the target
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/296e4f736086631e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/setup.rs:566
let head_name = head
.referent_name()
.map(|n| n.shorten().to_owned())
.unwrap_or_default();
if !head_name.starts_with(b"gitbutler/") {
anyhow::bail!("Not currently on a gitbutler/* branch.");
}
// When on gitbutler/edit, the project was already set up when entering edit mode.
// The workspace graph built from gitbutler/edit doesn't expose the target ref or
// remote configuration, but both are still configured in virtual_branches.toml
// and will be accessible when returning to gitbutler/workspace.
if head_name == b"gitbutler/edit" {
return Ok(true);
}
// TODO(legacy): it's fine to have no target.
if ws.graph.project_meta.target_ref.is_none() {
anyhow::bail!("No default target branch set.");
}
// check if there is a remote
if ws.push_remote_name().is_none()
&& repo
.remote_default_name(gix::remote::Direction::Push)
.is_none()
{
anyhow::bail!(
"Neither found push remote found in workspace nor unambiguously in the Git repository configuration."
)
};
Ok(true)
}
/// Creates a 'gb-local' remote pointing to this repository and creates tracking refs for the default branch.
fn setup_local_remote(repo: &gix::Repository, out: &mut OutputChannel) -> anyhow::Result<String> {View on GitHub (pinned to 58e5313667)