Files
lancedb/docs/src/js/classes/Branches.md
Brendan Clement d9018067b3 feat: support checking out a version on a branch (#3504)
### Description

Stacked on #3490. Adds an optional version to branch checkout across the
Rust core and the Python and TypeScript SDKs, so you can open a specific
version on a branch ("version V of branch B"), not just the branch's
latest version

Rust

```rust
// Open version 3 of branch "exp" (a read-only view): check out from an
// existing table, or open it directly from the connection.
let exp_v3 = table.checkout_branch("exp", Some(3)).await?;
let exp_v3 = db.open_table("items").branch("exp").version(3).execute().await?;
// checkout_latest re-attaches to the branch's writable HEAD.
exp_v3.checkout_latest().await?;

// With no branch, a version opens main at that version.
let main_v3 = db.open_table("items").version(3).execute().await?;
```

Python

```python
# Open version 3 of branch "exp" (a read-only view): check out from an
# existing table, or open it directly from the connection.
branch_v3 = await table.branches.checkout("exp", version=3)
branch_v3 = await db.open_table("items", branch="exp", version=3)
# checkout_latest re-attaches to the branch's writable HEAD.
await branch_v3.checkout_latest()

# With no branch, a version opens main at that version.
main_v3 = await db.open_table("items", version=3)
```

TypeScript

```typescript
// Open version 3 of branch "exp" (a read-only view): check out from an
// existing table, or open it directly from the connection.
const branchV3 = await (await table.branches()).checkout("exp", 3);
const opened = await db.openTable("items", undefined, { branch: "exp", version: 3 });
// checkoutLatest re-attaches to the branch's writable HEAD.
await branchV3.checkoutLatest();

// With no branch, a version opens main at that version.
const mainV3 = await db.openTable("items", undefined, { version: 3 });
```

### Testing
- Added unit tests (Rust, Python sync + async, TypeScript):
branch-scoped resolution at a version number shared with `main` and with
another branch, read-only enforcement on a pinned handle,
`checkout_latest` recovery to the branch's HEAD, fork-point reads, and
the nonexistent-version/branch error paths.
- Ran smoke tests against the Python and TypeScript SDKs on local
machine.
2026-06-08 17:36:38 -07:00

1.5 KiB

@lancedb/lancedbDocs


@lancedb/lancedb / Branches

Class: Branches

Branch manager for a Table.

Unlike tags, create and checkout return a new Table handle scoped to the branch; writes on it do not affect main.

Methods

checkout()

checkout(name, version?): Promise<Table>

Check out an existing branch and return a handle scoped to it.

With version set, the returned handle is pinned to that version of the branch (a read-only, detached view); otherwise it tracks the branch's latest and stays writable.

Parameters

  • name: string

  • version?: number

Returns

Promise<Table>


create()

create(
   name,
   fromRef?,
   fromVersion?): Promise<Table>

Create a branch and return a handle scoped to it.

Parameters

  • name: string Name of the new branch.

  • fromRef?: string Source branch to fork from. Defaults to main.

  • fromVersion?: number A specific version on fromRef. Defaults to latest.

Returns

Promise<Table>


delete()

delete(name): Promise<void>

Delete a branch.

Parameters

  • name: string

Returns

Promise<void>


list()

list(): Promise<Record<string, BranchContents>>

List all branches, mapping name to branch metadata.

Returns

Promise<Record<string, BranchContents>>