gitbutlerapp/gitbutler · error

branch ' ' no longer exists

Error message

branch '{}' no longer exists

What it means

Thrown by `branch_head_oid` when a branch recorded in a stored stack state no longer has a corresponding git reference in the repository. When reading or syncing stack heads (e.g. during oplog state restore or reference sync), each `StackBranch` name must resolve to an existing ref; if `try_find_reference` returns `None`, the branch was deleted externally.

Solutions

  1. Recreate the missing branch: `git branch <branch-name> <some-commit>` so the stored head can resolve
  2. Remove the stale branch from the GitButler workspace/stack state (e.g. `but branch delete` or unapply it in the UI)
  3. Restore a snapshot taken before the branch was deleted
  4. Re-apply the workspace (`but unapply` / `but apply`) so stack state is rebuilt from current refs

Example fix

// stored stack references branch 'feature-x' which was deleted
// before: branch 'feature-x' no longer exists
// after:
//   git branch feature-x 9c8b7a6f5e4d3c2b1a0f9e8d7c6b5a4f3e2d1c0b
Defensive patterns

Strategy: try-catch

Validate before calling

// before restoring, check all stack branches still resolve
for b in &stack_branches {
    if repo.try_find_reference(&b.name)?.is_none() {
        recreate_or_remove_branch(&b.name)?;
    }
}

Try / catch

// match on the error and heal state
match stack_head_oid(&stack, &repo) {
    Err(e) if e.to_string().contains("no longer exists") => {
        recreate_branch(&stack.name)?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: `restore_snapshot`/state restore calls `stack_head_oid` or `sync_branch_head_from_ref`, which calls `branch_head_oid` for a branch that was deleted via `git branch -D`, a rebase cleanup, or another tool while GitButler state still lists it.

Common situations: Deleting a branch with the git CLI while GitButler is open; branch deleted by a teammate and fetched state pruned it; switching machines with copied repos; force-pushes that removed remote branches backing local stack state.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/dc05ba3bd7c14b3f. Report an issue: GitHub.

Appendix: source

Thrown at crates/gitbutler-oplog/src/oplog.rs:742

    ) -> Result<gix::ObjectId> {
        if let Some(branch) = stack.heads.last() {
            branch_head_oid(branch, repo)
        } else {
            Ok(default_target_oid)
        }
    }

    pub(super) fn sync_stack_heads_from_refs(stack: &mut Stack, repo: &gix::Repository) -> bool {
        let mut changed = false;
        for head in &mut stack.heads {
            changed |= sync_branch_head_from_ref(head, repo).unwrap_or(false);
        }
        changed
    }

    fn branch_head_oid(branch: &StackBranch, repo: &gix::Repository) -> Result<gix::ObjectId> {
        let Some(mut reference) = repo.try_find_reference(&branch.name)? else {
            bail!("branch '{}' no longer exists", branch.name);
        };
        Ok(reference.peel_to_commit()?.id)
    }

    pub(super) fn set_reference_to_stored_head(
        branch: &StackBranch,
        repo: &gix::Repository,
    ) -> Result<()> {
        repo.reference(
            qualified_reference_name(&branch.name),
            branch.head,
            gix::refs::transaction::PreviousValue::Any,
            "GitButler reference",
        )?;
        Ok(())
    }

    fn sync_branch_head_from_ref(branch: &mut StackBranch, repo: &gix::Repository) -> Result<bool> {

View on GitHub (pinned to 58e5313667)