Sub topic 9
Versioning data without committing it to Git
This chapter assumes you can use Git (commit, tag, ignore files), you have the data/raw, data/interim, and data/processed layout from the previous chapter, and you can run commands in a terminal. The examples use DVC, an open-source tool for versioning data. The ideas also apply to similar tools.
Why Git is the wrong place for data
Git stores every version of every file in the repository's history. For source code this is cheap, because the files are small and changes compress well. For a 4 GB CSV file or a folder of 200,000 images it is not. Every clone downloads the whole history, and hosting services cap file and repository sizes. Git also cannot show a meaningful diff of a binary file.
You still need to know which data version produced which model. If the data changes and the commit does not, you cannot reproduce an old result. So you need a way to record the version of the data in Git without storing the data there.
The usual solution is to store a small pointer file in Git and the real bytes elsewhere:
- The pointer file holds a content hash (a fingerprint computed from the file's bytes), the size, and the path.
- The real data lives in a cache on your machine and in a remote, which is shared storage such as an S3 bucket, a shared disk, or another cloud store.
- Checking out a commit gives you the pointer for that commit. A second command fetches the matching data.
Setting up tracking
Start in a Git repository and initialize DVC:
pip install dvc
dvc init
git commit -m "Initialize DVC"dvc init creates a .dvc/ folder for configuration and a .dvcignore file. Both belong in Git.
Next, configure a remote and track the raw data folder. The bucket name below is a placeholder, so use your own storage:
dvc remote add -d storage s3://my-team-bucket/my_project
dvc add data/raw
git add data/raw.dvc data/.gitignore .dvc/config
git commit -m "Track raw data with DVC"
dvc pushdvc add data/raw does three things:
- It hashes the files and copies them into the local cache under
.dvc/cache. - It writes
data/raw.dvc, the pointer file. - It adds
/rawtodata/.gitignore, so Git never sees the data itself.
The -d flag on dvc remote add makes this remote the default. dvc push uploads the cached files to it.
What the pointer file contains
The .dvc file is short, human-readable YAML. The values below are illustrative:
outs:
- md5: a3f5c1d9e8b74260b1f0c2d3e4a59687.dir
size: 4203918211
nfiles: 1840
hash: md5
path: rawThe .dir suffix marks a directory. DVC stores a manifest listing every file and its hash, and the directory hash is computed from that manifest. If one file in the folder changes, the directory hash changes. That hash is the data version. Because Git versions this file, each Git commit is tied to exactly one version of the data.
Changing and restoring data
When the data changes, for example you add a new month of records, run the same sequence again:
dvc add data/raw
git add data/raw.dvc
git commit -m "Add November records to raw data"
git tag raw-2026-11
dvc pushOnly the new and changed files are uploaded, because DVC addresses files by hash and skips ones the remote already has.
To go back to an earlier version, restore the pointer and then the data:
git checkout raw-2025-10 -- data/raw.dvc
dvc checkoutThe first command puts the old pointer in your working tree. The second makes data/raw match it, fetching nothing if the files are already in your local cache. If they are not cached, run dvc pull instead. Remember to commit the restored pointer if you want to keep it.
A teammate who clones the repository gets the pointers only. They run:
dvc pullThis reads the pointers, downloads the matching files from the remote, and places them in the working folders.
What to track and what not to track
Track data that you cannot regenerate cheaply: the contents of data/raw, and any hand-labeled or purchased datasets. Raw data should be treated as read-only. Never edit it in place. Add a new version instead.
Data derived by code should usually not be tracked by hand. If data/processed is an output of a pipeline stage (as in the dvc.yaml from the pipeline chapter), the pipeline records its hash in dvc.lock. Running dvc add on a path that is already a stage output fails with an error, because two things would claim to own it.
Checking state
Two commands tell you whether things are in sync:
| Command | What it compares | Typical use |
|---|---|---|
| `dvc status` | Working folder against the pointer files | Did I change data without re-adding it? |
| `dvc status -c` | Local cache against the remote | Did I forget to push? |
| `dvc data status` | Working folder, cache, and Git together | A single summary of what is modified or uncommitted |
Choosing an approach
DVC is not the only option. The right choice depends on data size, team habits, and what you already run.
| Approach | How versions are stored | Strengths | Limits |
|---|---|---|---|
| Plain Git | Full file copies in history | No extra tools | Slow clones, size caps, bloated history |
| Git LFS | Pointer files, bytes on the Git host | Works with normal Git commands | Host storage quotas, files are versioned one at a time, no pipeline support |
| DVC | Pointer files, bytes in your own storage | Any storage backend, directory-level versions, links to pipelines | Extra commands to learn, two things to push |
| Bucket versioning only | Object versions inside the storage service | No new tooling | Versions are not tied to Git commits unless you record them yourself |
If you cannot adopt a tool, a minimum workable practice is to store each dataset version under an immutable path such as s3://bucket/datasets/2026-11-30/ and record that path and a checksum in a committed config file. This gives you the same guarantee, with more manual work.
Common problems
- Forgetting
dvc push. You commit the pointer, a teammate pulls, anddvc pullreports missing cache files. The pointer reached Git but the data never reached the remote. Rundvc status -cbefore sharing a branch. - Committing the data anyway. If
data/.gitignorewas not committed, or you usedgit add -f, the files enter Git history. Removing them later does not shrink the history. Checkgit statusbefore the first commit. - Editing data in place. DVC's default cache link type copies the files (using reflinks where the filesystem supports them), so edits are safe. If you switch to symlinks or hardlinks to save disk space, editing a tracked file can silently corrupt the cache entry. Treat tracked data as read-only in that case.
- Credentials in the repository. Put keys in environment variables or in
.dvc/config.local, which DVC keeps out of Git. Do not put them in.dvc/config, which you commit. - Folders with very many tiny files. Hashing and transferring hundreds of thousands of small files is slow. Pack them into archives or a columnar format such as Parquet before tracking.
- Untagged versions. A hash is hard to remember. A Git tag or a message that names the data version makes it easy to find the right commit later.
Exercise
A teammate pulls your branch and runs dvc pull, which fails with an error about missing files. git log shows you committed an updated data/raw.dvc. What most likely happened, which command would confirm it, and how do you fix it?
Show answer
You committed the pointer but did not run dvc push, so the remote does not have the new data. Run dvc status -c on your machine to confirm that the cache and the remote differ. Fix it by running dvc push, then ask the teammate to run dvc pull again.
Exercise
You tracked data/raw with dvc add. Today you receive a corrected version of one file in that folder. Describe the steps that record the new data version and let you return to the old one later.
Show answer
Replace the file in data/raw, then run dvc add data/raw, which changes the directory hash in data/raw.dvc. Commit data/raw.dvc with a message describing the correction, optionally add a Git tag, and run dvc push. To return to the old version later, run git checkout <old-commit-or-tag> -- data/raw.dvc followed by dvc checkout (or dvc pull if the old files are not in your cache).