Sub topic 9
Versioning Data Without Committing It to Git
This chapter assumes you know basic Git, command-line navigation, and how a training script reads files. The goal is to keep large datasets outside Git while preserving the exact data version used by each model.
Why Git Is Not Enough for Data
Git works well for source code and small text files. Large datasets create different problems:
- Repository clones become slow and large.
- Every changed binary file can consume more storage.
- Removing a file later does not necessarily remove its old contents from Git history.
- A Git commit may identify the code, but not the exact data downloaded from an external source.
A reproducible machine learning result needs a reference to a specific data version. That reference can be a content hash, a storage object version, or a tool-managed revision.
Keep Data Outside the Repository
A common layout keeps only small metadata files in Git:
| Item | Store in Git? | Typical location |
|---|---|---|
| Data download script | Yes | `src/my_project/data/` |
| Dataset manifest or checksum | Yes | `data/` or `manifests/` |
| Raw dataset | No | Object storage or a data-versioning cache |
| Processed dataset | Usually no | Object storage or pipeline cache |
| Configuration | Yes | `configs/` |
Add generated data to .gitignore:
data/raw/
data/interim/
data/processed/
models/Ignoring a path prevents new files from being staged. It does not remove files already tracked by Git. If a dataset was committed previously, remove it from the index with git rm --cached and consider the repository history before sharing it.
Use a Data Versioning Tool
Tools such as DVC store a small pointer file in Git and place the actual data in remote storage. The pointer records enough information to retrieve the same contents later.
A typical workflow looks like this:
dvc add data/raw/train.csv
git add data/raw/train.csv.dvc .gitignore
git commit -m "Track training data version"
dvc remote add -d storage s3://my-ml-data/project
dvc pushThe .dvc file belongs in Git. The CSV file does not. A teammate can check out the commit and run dvc pull to retrieve the data associated with that pointer.
Make Versions Meaningful
A data version should identify the input contents, not only a date or a friendly name. Record useful context alongside the pointer:
- Source system or download URL
- Collection or extraction date
- Schema version
- Filtering and labeling rules
- Personally identifiable information handling
- Checksums for external files
Treat raw data as immutable. If a correction is needed, create a new version instead of silently replacing the old one. Derived data should point back to the raw version and the code or configuration that produced it.
> callout note > Do not rely on a filename such as latest.csv. A moving name can silently change the training set. Resolve it to an immutable version before training.
Verify Retrieval Before Training
After cloning a project, retrieve the data and verify that the expected files exist:
git clone https://example.com/my-project.git
cd my-project
dvc pull
python -m my_project.data.prepare
python -m my_project.train --config configs/train.yamlA pipeline tool can also declare data as a dependency. When the raw data changes, the tool can identify which preparation and training stages must run again. This prevents a model from being compared with another model trained on an unknown input.
Exercise
Why should a dataset pointer be committed to Git while the dataset itself is stored remotely?
Show answer
The pointer connects a code commit to an immutable data version without making the Git repository store large binary files.