LinuxCommandLibrary

dolt-checkout

Switch between dolt branches or commits

TLDR

Switch to a branch

$ dolt checkout [branch_name]
copy

Revert unstaged changes to a table
$ dolt checkout [table]
copy

Create new branch and switch to it
$ dolt checkout -b [branch_name]
copy

Create new branch based on a specified commit and switch to it
$ dolt checkout -b [branch_name] [commit]
copy

SYNOPSIS

dolt checkout [options] [branch | commit] [--] [paths…]
dolt checkout [-b new-branch | -B new-branch] [start-point]
dolt checkout [--detach] [start-point]

PARAMETERS

-b, --branch
    Create new branch and switch to it (from current HEAD if no start-point)

-B
    Create/reset branch to start-point, even if it exists

--detach
    Detach HEAD to commit instead of switching branch

-l, --local
    Create local branch only (no remote tracking)

-q, --quiet
    Suppress progress output

-f, --force
    Force checkout, discarding local changes

-p, --patch
    Interactively patch files during restore

--orphan
    Create new orphan branch (empty history)

DESCRIPTION

Dolt checkout is a core command in Dolt, a Git-like version control system for SQL databases. It enables switching between branches, creating new branches, detaching HEAD to a specific commit, or restoring files in the working set from a tree-ish (branch, tag, or commit hash).

Like git checkout, it updates the index and working directory to match the tree-ish. Without paths, it performs branch switches, updating the database schema and data. With paths specified after --, it restores only those files, useful for undoing local changes.

Key behaviors:
dolt checkout <branch> switches to an existing branch, loading its full database state.
dolt checkout -b <new-branch> creates and switches to a new branch from the current HEAD.
dolt checkout <commit> -- <paths> restores specific SQL files or diffs.

This command ensures atomic switches, validating database consistency. It's essential for branching workflows in collaborative database development, where teams track schema evolutions and data changes over time. Note that checkout can be resource-intensive for large databases due to full state materialization.

CAVEATS

Checkout materializes full database state, slow for large DBs; uncommitted changes may be overwritten (use -f cautiously). Not for active read/write sessions.

EXAMPLES

dolt checkout main
dolt checkout -b feature-branch
dolt checkout HEAD~1 -- schema.sql

DOLT VS GIT DIFFERENCES

Unlike Git, restores full DB tables/schemas; supports dolt diff for data changes post-checkout.

HISTORY

Introduced in Dolt v0.1.0 (2019) by DoltHub team to mirror Git branching. Evolved with Dolt 1.0 (2023) for improved performance on large datasets and SQL-native diffs.

SEE ALSO

git-checkout(1), dolt-branch(1), dolt-switch(1), dolt-restore(1)

Copied to clipboard