Branches and database revisions allow you to work with your data at any commit in your database's commit graph. This is useful for isolating development on different branches, analyzing historical data, tracking data lineage, and much more.
Unlike other relational databases, Dolt has multiple heads, one for each branch in the database. A head can be a branch, a tag, or a working set. Multiple clients can connect to each branch, and will see other writes to the same branch following the normal SQL transactional isolation semantics (REPEATABLE_READ). In effect, each branch functions as its own isolated database instance, with changes only visible to other clients connected to the same branch.
A Dolt database server with multiple heads
A database server has a default branch, which is the checked-out branch at the time the server was started. Using database revision specifiers, clients can choose a specific branch, tag, or commit to pin their queries to.
The exact connection string you need to use will vary depending on your client.
To connect to the default branch, use a connection string with the name of the database only.
To connect to a different branch, specify that branch name with a slash after the database name:
To connect to a specific revision of the database, use a commit hash or tag instead of a branch name. The database will be read-only in this case.
You can also use the same ancestry syntax as Git to reference specific parent commits in a connection string, or anywhere else you would use a database revision specifier. For example,
mysql://127.0.0.1:3306/mydb/feature-branch~2will connect you to a read-only database for the grandparent commit of the
This also works with the standard MySQL command line client:
mysql --host 127.0.0.1 --port 3306 -u root mydb/feature-branch
Similar to the examples above, you can issue
USEstatements to select a database revision, too.
USE mydbswitches to the default branch.
To switch to a named branch:
Note that the string must be back-tick quoted, since it contains a
To switch to a read-only database at a commit hash or tag:
You can also use fully-qualified names with database revisions in your queries. For example, the following query references a specific branch of a database by using a fully-qualified name that includes a revision specification:
SELECT * from `mydatabase/feature-branch`.accounts;
You can use the same syntax for specific commits:
SELECT * from `mydatabase/ia1ibijq8hq1llr7u85uivsi5lh3310p`.accounts;
and for tags:
SELECT * from `mydatabase/v1.0`.accounts;
DOLT_CHECKOUT()SQL procedure provides identical functionality to the
dolt checkoutcommand on the command line, and accepts the same arguments.
CALL DOLT_CHECKOUT('feature-branch');switches the session to the
feature-branchbranch. You can also switch to a new branch, like so:
CALL DOLT_CHECKOUT('-b', 'new-branch');
You can switch to a new branch with a starting commit as well:
CALL DOLT_CHECKOUT('-b', 'new-branch-at-commit', 'ia1ibijq8hq1llr7u85uivsi5lh3310p')
If you have outstanding changes in your session (because you have issued DML or DDL statements to change the data or schema), you must
ROLLBACKthe transaction before switching branches.