gitbutlerapp/gitbutler · error

Could not find branch: {branch_id}

Error message

Could not find branch: {branch_id}

What it means

`but land <id>` resolves the identifier through the per-workspace IdMap (land/mod.rs:42-46). An empty result set means the ID matches nothing known in this workspace — typo, stale short ID, or wrong project — and the handler bails before reading configuration or touching anything.

Source

Thrown at crates/but/src/command/legacy/land/mod.rs:45

    // runs here for a friendly message before the prompt; the API enforces it again, along with the
    // bottom-segment, conflicted-commit, and triangular-remote guards, before mutating anything.
    let (branch_name, base_branch) = {
        let mut guard = ctx.exclusive_worktree_access();

        {
            let (_repo, ws, _db) = ctx.workspace_and_db_with_perm(guard.read_permission())?;
            if !ws.kind.has_managed_ref() {
                bail!(
                    "`but land` requires an active GitButler workspace (`gitbutler/workspace`). \
                     Switch into the workspace and try again."
                );
            }
        }

        let id_map = IdMap::new_from_context(ctx, guard.read_permission())?;
        let resolved_ids = id_map.parse_using_context(branch_id, ctx)?;
        if resolved_ids.is_empty() {
            bail!("Could not find branch: {branch_id}");
        }
        if resolved_ids.len() > 1 {
            bail!("Ambiguous branch '{branch_id}', matches multiple items");
        }

        let branch_name = match &resolved_ids[0] {
            CliId::Branch(branch) => branch.name.clone(),
            other => bail!("Expected a branch ID, got {}", other.kind_for_humans()),
        };

        let base_branch =
            but_api::legacy::virtual_branches::get_base_branch_data(ctx, guard.write_permission())?
                .ok_or_else(|| anyhow::anyhow!("No base branch configured"))?;
        (branch_name, base_branch)
    };

    // Display strings for the prompt and the final report. The API recomputes the target/remote
    // configuration internally; the CLI only needs these names to describe what's about to happen.

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Run `but status` in the same directory and re-copy the branch ID.
  2. Use the branch's full name instead of a short ID.
  3. Confirm you are in the right repo/project before retrying.

Example fix

# before
but land b7      # stale/typo'd ID -> Could not find branch: b7

# after
but status       # copy the current lane ID or name
but land <fresh-id> --yes
Defensive patterns

Strategy: validation

Validate before calling

# Resolve first: the ID must appear in this workspace's status
but status | grep -F '<id>' || { echo 'unknown branch id'; exit 2; }
but land '<id>' --yes

Prevention

When it happens

Trigger: `but land <id>` where `IdMap::parse_using_context` returns no entries: typo'd prefixes, IDs copied from another workspace or an older `but status`, or IDs invalidated by rebase/squash operations that rebuilt the map.

Common situations: Short IDs going stale after the workspace rewrites history; switching between multiple GitButler projects; fat-fingering the copied ID.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/fc8a68450696b267. Report an issue: GitHub.