Sub topic 11
Reusing Data Across Repositories
Assume you know basic Git commands, can read YAML, and have DVC installed. This chapter shows how to consume data owned by another DVC repository without copying its files into your Git repository.
Why reuse data from another repository
Teams often keep shared datasets in a dedicated repository. A training repository can then use that dataset instead of maintaining a second copy. DVC provides two commands for this purpose:
dvc getdownloads a version of a file or directory once.dvc importdownloads the data and records its source so the dependency can be updated later.
Both commands identify data by a repository URL, a path inside that repository, and optionally a Git revision such as a tag or commit.
Downloading a snapshot with `dvc get`
Use dvc get when you need a one-time copy. The command downloads the requested data into your current project, but it does not create a tracked relationship with the source repository.
dvc get https://github.com/iterative/dataset-registry \
get-started/data.xml \
--rev main \
-o data/data.xmlThe source path is get-started/data.xml. The -o option chooses the destination in your project. You can commit the downloaded file to Git or track it with dvc add, but later changes in the source repository will not update this copy automatically.
This approach is useful for a temporary example, a one-time migration, or a dataset that should become independent after download.
Tracking a dependency with `dvc import`
Use dvc import when your project should remember where the data came from.
mkdir -p data
dvc import https://github.com/iterative/dataset-registry \
get-started/data.xml \
--rev main \
-o data/data.xml
git add data/data.xml.dvc data/.gitignore
git commit -m "Import shared dataset"DVC downloads the data, creates a small data/data.xml.dvc file, and usually adds the data file to .gitignore. The .dvc file contains the source URL, source path, revision, and checksum. Git versions this metadata, while DVC manages the data itself.
A source revision is important. Without one, the meaning of main can change as the source repository receives commits. For reproducible training, prefer a tag or commit hash:
dvc import https://github.com/iterative/dataset-registry \
get-started/data.xml \
--rev v1.0.0 \
-o data/data.xmlUpdating an imported dataset
An imported file is a dependency, so you can update it when the source repository publishes a newer revision.
dvc update data/data.xml.dvc --rev v1.1.0
git add data/data.xml.dvc data/.gitignore
git commit -m "Update imported dataset to v1.1.0"dvc update changes the pointer file and downloads the new content. The old version remains recoverable through Git if its pointer file was committed and the required data still exists in a DVC cache or remote.
| Command | Records source relationship | Best use |
|---|---|---|
| `dvc get` | No | One-time download |
| `dvc import` | Yes | Reproducible shared dependency |
Common errors
- Importing
mainwithout recording a stable revision can make later reproduction ambiguous. - Committing the downloaded data itself defeats the purpose of DVC for large files.
- Running
dvc updatewithout committing the changed.dvcfile leaves teammates on the older version. - A private source repository or remote may require credentials in both local development and CI.
Exercise
You need a reproducible training project that consumes version v2.0.0 of a dataset maintained elsewhere. Which command should you use, and what should you commit?
Show answer
Use dvc import with --rev v2.0.0. Commit the generated .dvc pointer file and the relevant .gitignore change, not the large downloaded dataset.