The one-line mental model
Git versions code but not gigabytes; DVC extends Git with pointer files and an external content-addressable store so a commit pins the exact dataset, model, and pipeline stage outputs that produced your results.
You will be able to:
- Initialize DVC with a remote storage backend (S3, GCS, or local)
- Track large files with
dvc addand commit the resulting.dvcpointers - Define a multi-stage pipeline in
dvc.yamlthat is reproducible with one command - Use
dvc checkoutanddvc pullto move between data versions like Git branches
Prerequisites
- !Git basics: add, commit, branch, remote
- !Python environment and requirements management
- !Comfort with a command line and YAML
What You'll Learn
- 1Explain the pointer-file architecture that keeps Git repositories small
- 2Configure an S3 or GCS remote and sync tracked artifacts
- 3Author a pipeline stage with deps, outs, and params
- 4Reproduce an entire experiment from a clean checkout with dvc reproduce
The pointer-file architecture
DVC does not stuff large binaries into Git. Instead dvc add moves the file into a local cache (.dvc/cache), writes an .dvc pointer file into the working tree, and adds a small .gitignore entry so Git tracks only the pointer. The pointer contains an MD5 hash of the content; the remote store (S3, GCS, Azure, or a plain directory) holds the actual bytes. Checking out a different Git commit and running dvc checkout swaps the real files to match the pointers recorded in that commit.
my-project/
āāā .git/ # code + .dvc pointer files only
āāā .dvc/
ā āāā config # remote URL, cache settings
ā āāā cache/ # content-addressed local cache
āāā data/
ā āāā raw/
ā ā āāā orders.csv # gitignored real file
ā ā āāā orders.csv.dvc # committed pointer
ā āāā processed/
ā āāā features.parquet.dvc
āāā models/
ā āāā churn_rf.joblib.dvc
āāā dvc.yaml # pipeline definition
āāā params.yaml # hyperparameters, versions
āāā requirements.txt
| Concept | Role | Analog in Git |
|---|---|---|
.dvc file | Pointer to content in cache/remote | Blob reference |
.dvc/cache | Local content-addressed storage | .git/objects |
| Remote | Shared object store (S3, GCS) | origin server |
dvc.yaml | Pipeline stages with deps and outs | Makefile / CI job |
params.yaml | Versioned hyperparameters | Config file |
The separation is what keeps git clone fast ā the repository stays kilobytes while terabyte datasets live in cheap object storage, versioned by the same commit history as your code.
Setting up a remote
A remote is just a URL where DVC uploads and downloads cache objects. S3 and GCS are the production defaults; a network share or another developer's directory works for local pair programming. Credentials flow through the cloud SDK's normal environment variables, never through the repo.
# One-time project setup
git init
dvc init
git add .dvc .gitignore
git commit -m "Initialize DVC"
# S3 remote (team default)
dvc remote add -d storage s3://my-org-ml-bucket/experiments
dvc remote modify storage access_grants \
profile my-profile
git add .dvc/config
git commit -m "Configure S3 remote"
# Or GCS
# dvc remote add -d storage gs://my-org-ml-bucket/experiments
# Or a local directory for pair programming
# dvc remote add -d storage /mnt/shared/ml-store
# Verify connectivity
dvc remote list
Once the remote is configured, dvc push uploads any cache objects not yet present, and dvc pull fetches them on a fresh clone. The remote is content-addressed, so identical files across branches or experiments are stored once.
Tracking data and models
dvc add is the analog of git add for large files. It creates the pointer, updates .gitignore, and leaves the real file untouched in your working tree. Committing the .dvc file pins that content to a Git revision.
# Track a raw dataset
dvc add data/raw/orders.csv
git add data/raw/orders.csv.dvc .gitignore
git commit -m "Add raw orders dataset v3"
# Track a processed feature store
dvc add data/processed/features.parquet
git add data/processed/features.parquet.dvc .gitignore
git commit -m "Add feature snapshot for churn model"
# Track a trained model artifact
dvc add models/churn_rf.joblib
git add models/churn_rf.joblib.dvc .gitignore
git commit -m "Baseline random forest, ROC-AUC 0.84"
# Push everything to the remote
dvc push
To return to the dataset as it existed three commits ago, check out the Git revision and let DVC restore the matching files:
git log --oneline -5
git checkout HEAD~3 -- data/raw/orders.csv.dvc
dvc checkout data/raw/orders.csv.dvc
# data/raw/orders.csv is now the exact bytes from HEAD~3
The mental model is exact: Git decides which version the pointer refers to, DVC materializes the content behind it. Nothing about the dataset lives in Git history bloat.
Parameters as versioned config
params.yaml holds every knob a pipeline stage depends on ā learning rates, split fractions, feature lists ā and DVC tracks changes to it like any other file. A stage that declares params: in dvc.yaml re-runs automatically when the relevant keys change, which is exactly the invalidation logic you want for hyperparameter sweeps.
# params.yaml
data:
raw_path: data/raw/orders.csv
processed_path: data/processed/features.parquet
test_size: 0.2
features:
numeric: [age, income, tenure_days, order_count]
categorical: [region, plan]
model:
n_estimators: 300
max_depth: 8
min_samples_leaf: 5
random_state: 42
eval:
primary_metric: roc_auc
gate: 0.80
Because params.yaml is committed, every experiment's configuration is recoverable from the commit hash alone ā no more "which branch had max_depth=6?" archaeology.
Defining the pipeline in dvc.yaml
dvc.yaml declares stages as a DAG: each stage has a command, input dependencies (deps), parameter dependencies (params), and output artifacts (outs). dvc reproduce walks the DAG in topological order, skipping stages whose deps and params have not changed ā a content-based build system for data science.
# dvc.yaml
stages:
prepare:
cmd: python src/prepare.py
deps:
- src/prepare.py
- data/raw/orders.csv
params:
- data.test_size
outs:
- data/processed/train.csv
- data/processed/test.csv
features:
cmd: python src/features.py
deps:
- src/features.py
- data/processed/train.csv
- data/processed/test.csv
params:
- features.numeric
- features.categorical
outs:
- data/processed/features.parquet
train:
cmd: python src/train.py
deps:
- src/train.py
- data/processed/features.parquet
params:
- model.n_estimators
- model.max_depth
- model.min_samples_leaf
- model.random_state
outs:
- models/churn_rf.joblib
- metrics/train_metrics.json
metrics:
- metrics/train_metrics.json:
cache: false
evaluate:
cmd: python src/evaluate.py
deps:
- src/evaluate.py
- models/churn_rf.joblib
- data/processed/test.csv
params:
- eval.primary_metric
- eval.gate
metrics:
- metrics/eval_metrics.json:
cache: false
outs:
- reports/confusion_matrix.png:
cache: false
The metrics: key tells DVC these files hold scalar metrics the UI can display; cache: false keeps them in Git rather than the remote store, since they are small and diffable. Reproducing an entire run from a clean checkout is then a single command.
# Fresh clone: code + pointers only
git clone git@github.com:my-org/churn-model.git
cd churn-model
dvc pull # fetch pointer contents from remote
# Reproduce the full pipeline (skips stages already up to date)
dvc reproduce
# Change one hyperparameter and re-run only the affected stages
# (edit params.yaml: model.max_depth: 12)
dvc reproduce train evaluate
# Visualize the DAG
dvc dag
Because stage commands are plain Python scripts with no DVC imports, the same code runs unchanged in CI, on a colleague's laptop, or inside a container ā DVC only orchestrates and tracks.
Reproducibility and experiment workflows
The combination of Git branches, DVC-tracked data, and dvc.yaml stages gives you experiment branching: branch the repo, change params.yaml, run dvc reproduce, and compare dvc metrics show across runs. dvc exp adds a lighter-weight experiment namespace that does not require a Git commit per trial.
# Run a sweep without polluting Git history
dvc exp run --set-param model.max_depth=6 \
--set-param model.n_estimators=500
dvc exp run --set-param model.max_depth=10 \
--set-param model.n_estimators=200
# Compare experiments
dvc exp show --sort-by eval_metrics.roc_auc --desc
# Apply the winning experiment to a real branch
dvc exp apply <exp-name>
git checkout -b experiment/deeper-trees
git add params.yaml
git commit -m "Try deeper trees from dvc experiment"
dvc push
For teams, dvc exp share publishes experiments to the remote server so reviewers can inspect metrics and artifact diffs without pulling every branch. This workflow keeps the main branch clean while still recording every trial's configuration and outcome.
When DVC is not enough
DVC versions files and pipelines; it does not version rows inside a live warehouse table, stream features in real time, or replace a feature store's online serving layer. For warehouse-native datasets, pair DVC with dbt or a table-level snapshot tool; for real-time features, use a feature store. DVC's sweet spot is the offline world: training snapshots, labeled datasets, serialized models, and the DAG that connects them ā exactly the artifacts a reproducible ML project cannot live without.
Understanding this boundary prevents the common over-adoption failure: trying to force DVC to manage streaming pipelines or live feature stores it was never designed for. DVC's content-addressed model works beautifully for batch artifacts that change infrequently and can be snapshotted; it is the wrong tool for data that updates every few seconds or for features that must be served with single-digit-millisecond latency. Recognize the seam between offline versioning (DVC's domain) and online serving (a feature store's domain) early, and design the handoff ā typically a materialized batch feature table that both training and serving consume ā as an explicit interface rather than an afterthought.