Git For Data
Dolt is Git for Data. You can use Dolt's command line interface to version control data like you version control files with Git. Git versions files, Dolt versions tables.
All the commands you know for git work the same with dolt, but with tables instead of file names. Follow along with the tutorial below to learn the basics.

Configure Dolt

After installing Dolt, the first thing you must do to use it like Git for Data is set the user.name and user.email config variables. This information will be used to attribute each Dolt commit to you.
1
dolt config --global --add user.name <your name>
2
dolt config --global --add user.email <your email>
Copied!

Create a repository

dolt init creates a repository, just like git init.
1
% dolt init
2
Successfully initialized dolt data repository.
Copied!

Import some data

Dolt can import most data file types. This example uses CSV.
We'll create a simple data file with state populations.
1
% cat > states.csv <<EOF
2
state,population
3
Delaware,59096
4
Maryland,319728
5
Tennessee,35691
6
Virginia,691937
7
Connecticut,237946
8
Massachusetts,378787
9
South Carolina,249073
10
New Hampshire,141885
11
Vermont,85425
12
Georgia,82548
13
Pennsylvania,434373
14
Kentucky,73677
15
New York,340120
16
New Jersey,184139
17
North Carolina,393751
18
Maine,96540
19
Rhode Island,68825
20
EOF
Copied!
Then import it as a dolt table:
1
% dolt table import -c -pk=state state_populations states.csv
2
Rows Processed: 17, Additions: 17, Modifications: 0, Had No Effect: 0
3
Import completed successfully.
Copied!

View the status

dolt status does the same thing as git status.
1
% dolt status
2
On branch main
3
Untracked files:
4
(use "dolt add <table|doc>" to include in what will be committed)
5
new table: state_populations
Copied!

Create a commit

Add tables with dolt add, commit them with dolt commit. Both these commands work just like their git equivalents.
1
% dolt add .
2
% dolt commit -m "State population data"
3
commit b1aa1bbkvlblnasohleec9ga9pieo9ts
4
Author: Zach Musgrave <[email protected]>
5
Date: Mon Dec 06 17:58:06 -0800 2021
6
7
State population data
Copied!

View the log

dolt log does the same thing as git log, and shows us the history of the database.
1
% dolt log
2
commit b1aa1bbkvlblnasohleec9ga9pieo9ts
3
Author: Zach Musgrave <[email protected]>
4
Date: Mon Dec 06 17:58:06 -0800 2021
5
6
State population data
7
8
commit 62dsa7mrbkre939n56m94dfl3cl75k20
9
Author: Zach Musgrave <[email protected]>
10
Date: Mon Dec 06 17:23:35 -0800 2021
11
12
Initialize data repository
Copied!

Create a branch

Just like in git, it's a good idea to make your changes on a branch, then merge them back to main. The commands work the same as in git. Use either dolt branch or more commonly, dolt checkout -b to create a new branch.
1
% dolt checkout -b feature
2
Switched to branch 'feature'
Copied!

Change the data using SQL

To change the data, use SQL INSERT, UPDATE and DELETE statements. Dolt has a built-in SQL shell, or start a server and connect to it with any tool that can connect to MySQL.
1
% dolt sql
2
# Welcome to the DoltSQL shell.
3
# Statements must be terminated with ';'.
4
# "exit" or "quit" (or Ctrl-D) to exit.
5
state_pops> update state_populations set population = 0 where state like 'New%';
6
Query OK, 3 rows affected
7
Rows matched: 3 Changed: 3 Warnings: 0
8
state_pops> exit
9
Bye
Copied!
You can also run individual queries from the command line with dolt sql -q.

View the diff

1
% dolt diff
2
diff --dolt a/state_populations b/state_populations
3
--- a/state_populations @ msmov4aocgno3klji3d2kk2qsg405urr
4
+++ b/state_populations @ 4op7rpaqg0a62lkomf2b1b8e6tt3gug4
5
+-----+---------------+------------+
6
| | state | population |
7
+-----+---------------+------------+
8
| < | New Hampshire | 141885 |
9
| > | New Hampshire | 0 |
10
| < | New Jersey | 184139 |
11
| > | New Jersey | 0 |
12
| < | New York | 340120 |
13
| > | New York | 0 |
14
+-----+---------------+------------+
Copied!

Commit and merge

1
% dolt add .
2
% dolt commit -m "Only original states now"
Copied!
After commiting on the feature branch, checkout main and merge your changes back. dolt merge works just like git merge.
1
% dolt checkout main
2
Switched to branch 'main'
3
% dolt merge feature
4
Updating b1aa1bbkvlblnasohleec9ga9pieo9ts..9a1mbpq7kva50ibhmru4viiqutmiqmmm
5
Fast-forward
Copied!

Next steps

Keep reading the getting started guide to learn more, or skip to the full CLI docs.
Last modified 1mo ago