gitbutlerapp/gitbutler · error
snapshot checkout ref is not a local branch
Error message
snapshot checkout ref is not a local branch
What it means
Thrown by `snapshot_checkout` during snapshot restore when the blob storing the checkout ref name parses as a valid `gix::refs::FullName` but its category is not a local branch (e.g. it is a tag, remote branch, or another kind of ref). GitButler only supports restoring snapshots onto local branches, so any other ref category is rejected.
Solutions
- Ensure the branch you want to restore onto exists as a local branch (`git branch <name> <commit>`) before restoring
- Check the snapshot's checkout-ref blob (`git ls-tree` on the snapshot tree) and confirm it stores `refs/heads/...`
- Restore an earlier snapshot entry whose checkout ref is a local branch
- If migrating between repos, create the local branch in the target repo to match the snapshot's ref name
Example fix
// snapshot stores a non-branch ref // before: refs/remotes/origin/main // after (create local branch first, then snapshot references it): // git branch main origin/main -> refs/heads/main
Defensive patterns
Strategy: validation
Validate before calling
fn checkout_ref_is_local_branch(snapshot: &SnapshotMetadata) -> bool {
snapshot.checkout_ref()
.map(|r| r.as_bstr().starts_with(b"refs/heads/".as_bstr()))
.unwrap_or(false)
} Prevention
- Only take snapshots while local branches are checked out
- Ensure target branches exist locally before restoring snapshots migrated across repos
- Avoid storing remote-tracking or tag refs as snapshot checkout targets
- Inspect the snapshot ref blob (`git ls-tree`) before scripted restores
When it happens
Trigger: `restore_snapshot` -> `snapshot_checkout` encounters a snapshot whose checkout-ref blob contains e.g. `refs/remotes/origin/main`, `refs/tags/v1`, or a non-branch ref instead of `refs/heads/<branch>`.
Common situations: Snapshots taken while the workspace pointed at a remote-tracking ref; manual manipulation of the oplog tree; restoring a snapshot across repos where ref layouts differ; snapshots created by older versions with different ref naming.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Expected a local branch, but
- Branch ' ' already exists
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Branch name ' ' collides with existing branch
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/ffd895a617275756.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-oplog/src/oplog.rs:589
}
fn snapshot_checkout(
snapshot_tree: &gix::Tree<'_>,
repo: &gix::Repository,
) -> Result<Option<SnapshotCheckout>> {
let Some(ref_entry) = snapshot_tree.lookup_entry_by_path("checkout/ref")? else {
return Ok(None);
};
let commit_entry = snapshot_tree
.lookup_entry_by_path("checkout/commit")?
.context("snapshot checkout ref has no commit")?;
let ref_blob = repo
.find_blob(ref_entry.id())
.context("failed to read snapshot checkout ref")?;
let ref_name = gix::refs::FullName::try_from(ref_blob.data.as_bstr())
.context("snapshot checkout ref is invalid")?;
if ref_name.category() != Some(gix::refs::Category::LocalBranch) {
bail!("snapshot checkout ref is not a local branch");
}
let commit_blob = repo
.find_blob(commit_entry.id())
.context("failed to read snapshot checkout commit")?;
let commit_id = gix::ObjectId::from_hex(&commit_blob.data)
.context("snapshot checkout commit is invalid")?;
if commit_id.is_null() {
bail!("snapshot checkout commit is null");
}
Ok(Some(SnapshotCheckout {
ref_name,
commit_id,
}))
}
fn snapshot_metadata(
snapshot_tree: &gix::Tree<'_>,
repo: &gix::Repository,View on GitHub (pinned to 58e5313667)