gitbutlerapp/gitbutler · error

targetRef in project_meta.toml is not a remote-tracking…

Error message

targetRef in project_meta.toml is not a remote-tracking branch

What it means

When loading a snapshot's project metadata back from project_meta.toml, the stored targetRef string is parsed as a gix::refs::FullName and must be a remote-tracking branch (refs/remotes/...). If the ref name is unparseable the context reports 'invalid targetRef'; if it parses but names any other ref category (local branch, tag, etc.) this bail fires, because snapshot restore requires a remote-tracking target.

Solutions

  1. Set the project target to a remote-tracking branch (refs/remotes/<remote>/<branch>) before taking snapshots you may need to restore.
  2. Edit project_meta.toml in the snapshot to correct targetRef to a refs/remotes/... full name.
  3. Push the target branch to a remote and re-point the target, then retake the snapshot.
  4. If the snapshot is unrecoverable, restore workspace state manually rather than via oplog restore.

Example fix

// before (project_meta.toml inside snapshot)
targetRef = "refs/heads/main"
// after
targetRef = "refs/remotes/origin/main"
Defensive patterns

Strategy: validation

Validate before calling

let name: gix::refs::FullName = target_ref.parse()?;
assert_eq!(name.category(), Some(gix::refs::Category::RemoteBranch),
    "target must be a remote-tracking branch");

Type guard

fn is_remote_tracking_ref(name: &str) -> bool {
    gix::refs::FullName::try_from(name.to_owned()).ok()
        .and_then(|n| n.category().map(|c| c == gix::refs::Category::RemoteBranch))
        .unwrap_or(false)
}

Try / catch

match restore_snapshot(&ctx, id) {
    Err(e) if e.to_string().contains("not a remote-tracking branch") => {
        // repair metadata or restore manually
    }
    other => other?,
}

Prevention

When it happens

Trigger: Restoring an oplog snapshot whose project_meta.toml contains a targetRef pointing at a non-remote-tracking ref, e.g. refs/heads/main instead of refs/remotes/origin/main, or a malformed/garbage ref string.

Common situations: Projects whose target was set to a local-only branch when the snapshot was taken; manual edits to project_meta.toml; older/other tooling writing a different ref format; hand-crafted test snapshots.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

            target_ref: meta.target_ref.as_ref().map(ToString::to_string),
            target_commit_id: target_commit_id.to_string(),
            push_remote: meta.push_remote.clone(),
        })
    }
}

impl TryFrom<SnapshotProjectMeta> for ProjectMeta {
    type Error = anyhow::Error;

    fn try_from(meta: SnapshotProjectMeta) -> Result<Self> {
        let target_ref = meta
            .target_ref
            .map(|name| {
                let name: gix::refs::FullName = name
                    .try_into()
                    .context("invalid targetRef in project_meta.toml")?;
                if name.category() != Some(gix::refs::Category::RemoteBranch) {
                    bail!("targetRef in project_meta.toml is not a remote-tracking branch");
                }
                Ok(name)
            })
            .transpose()?;
        let target_commit_id = gix::ObjectId::from_str(&meta.target_commit_id)
            .context("invalid targetCommitId in project_meta.toml")?;
        if target_commit_id.is_null() {
            bail!("targetCommitId in project_meta.toml is null");
        }
        Ok(Self {
            target_ref,
            target_commit_id: Some(target_commit_id),
            push_remote: meta.push_remote,
        })
    }
}

/// The Oplog allows for crating snapshots of the current state of the project as well as restoring to a previous snapshot.

View on GitHub (pinned to 58e5313667)