Sub topic 1
Why Git is not enough for data and models
Prerequisites
This chapter assumes you know basic Git: commit, branch, tag, and checkout. You should be comfortable running commands in a terminal and have DVC installed (pip install dvc). Later chapters also use Python and YAML.
Why Git struggles with large files
Git stores every version of every tracked file in its object database. It handles text well because text diffs are small and compress well. Large binary files, such as a 2 GB CSV or a trained model, do not behave this way. Each changed copy adds another full copy to the repository, so clones grow slow and large. Git LFS moves the bytes to a separate server, but you still need a way to link each commit to the exact data it used.
DVC fills that gap. It keeps small metadata files in Git and stores the large files elsewhere.
Setting up a DVC project
A DVC project is a Git repository with DVC added on top. Start with:
git init
dvc init
git commit -m "Initialize DVC"dvc init creates a .dvc/ directory that holds DVC's configuration and cache settings. Commit it so collaborators get the same setup.
Tracking data with dvc add
Run dvc add on a file to start tracking it:
dvc add data/raw.csv
git add data/raw.csv.dvc data/.gitignore
git commit -m "Track raw data with DVC"dvc add moves the file's content into the DVC cache, links the workspace file back to the cache, and writes data/raw.csv.dvc. That pointer file records the content hash. It also adds raw.csv to data/.gitignore, so Git ignores the data itself.
How the DVC cache stores your files
DVC names each cached file by its content hash, so identical content is stored once. The cache lives in .dvc/cache.
| Item | Where it lives | What versions it |
|---|---|---|
| Data file | Workspace, linked to cache | Its hash in the `.dvc` file |
| Pointer file | Git repository | Git |
| Content | `.dvc/cache` | DVC, by hash |
Exercise
After dvc add data/raw.csv, which files should you commit to Git?
Show answer
Commit data/raw.csv.dvc and data/.gitignore. Do not commit data/raw.csv, because Git would store the full file.