Sub topic 5
Sharing data through a remote
This chapter assumes you can run dvc init and dvc add, and that you know Git remotes, commits, and clones. It also assumes you know the pointer-file idea: Git stores a small .dvc file and DVC stores the data in a local cache. Here you will move that data off your machine so teammates, CI jobs, and your future self can get it back.
What a DVC remote is
Git stores your pointer files. The data they point to lives in the DVC cache, and the cache is local to your clone. If you delete the clone, or a colleague clones the repository, the pointer files arrive but the data does not.
A DVC remote is shared storage that holds copies of cache files. It plays the same role for data that origin plays for commits. A few differences matter in practice:
- A DVC remote is not a Git remote. Pushing commits with
git pushnever uploads data. - A DVC remote stores content in the same layout as the local cache. Files are named by their content hash, so you cannot browse it for
raw.csv. - Any storage that your team can read and write can serve as a remote. DVC supports Amazon S3 and S3-compatible stores, Google Cloud Storage, Azure Blob Storage, SSH/SFTP servers, WebDAV, HDFS, and plain directories (local disks or network mounts). HTTP remotes are read-only.
Each backend needs its own optional dependency. For S3 you install pip install "dvc[s3]". Other extras include dvc[gs], dvc[azure], and dvc[ssh].
The local cache sits in the middle of every transfer. Data never goes straight from the workspace to the remote, and it never comes straight back.
Configuring a remote
Add a remote and make it the default with -d:
dvc remote add -d storage s3://my-bucket/dvc-store
git add .dvc/config
git commit -m "Configure default DVC remote"The command writes to .dvc/config, which is a tracked file. The result looks like this:
[core]
remote = storage
['remote "storage"']
url = s3://my-bucket/dvc-storeCommitting this file matters. After a git clone, the collaborator already knows where the data lives and can run dvc pull without further setup.
You can configure several remotes. The one named under core.remote is the default. Commands that move data accept -r NAME to pick another one.
dvc remote list
dvc remote default storage
dvc remote modify storage url s3://my-bucket/new-prefixCredentials stay out of Git
.dvc/config is committed, so it must not hold secrets. DVC reads a second file, .dvc/config.local, which dvc init adds to .gitignore. Use the --local flag to write values there:
dvc remote modify --local storage access_key_id 'AKIA...'
dvc remote modify --local storage secret_access_key '...'For cloud providers it is usually better to skip DVC settings altogether and rely on the provider's normal credential chain. For S3 that means environment variables, a shared credentials file, or an instance role. If you use named profiles, a profile name is not a secret, so you can commit it:
dvc remote modify storage profile team-dataA rule of thumb: URLs, regions, and profile names go in .dvc/config. Keys, tokens, and passwords go in .dvc/config.local or in the environment.
Uploading with dvc push
dvc push looks at the pointer files and dvc.lock files in your current workspace. It uploads every referenced cache file that the remote does not already have.
dvc pushThe remote only receives missing files. If you changed one file in a directory of 10,000 images and ran dvc add again, the push uploads the changed file and the new directory listing. The other 9,999 files are already there under their hashes.
Some options you will use:
| Command | What it does |
|---|---|
| `dvc push` | Uploads data for the current workspace to the default remote |
| `dvc push -r backup` | Uploads to the remote named `backup` |
| `dvc push data/raw.csv.dvc` | Uploads only the data referenced by that pointer file |
| `dvc push -A` | Uploads data for every commit in the repository (`--all-commits`, `--all-branches`, and `--all-tags` narrow this) |
| `dvc push -j 8` | Uses 8 parallel transfers |
By default, dvc push covers only the commit you have checked out. If you tagged v1.0, moved on to v2.0, and never pushed from v1.0, that older data stays unshared unless you use -A or --all-tags. Teammates who check out v1.0 later will find missing files.
The order of publishing matters. Push data first, then commits:
dvc push
git pushIf you push the commit first, someone can pull a pointer file whose data is not yet in the remote. Pushing data first avoids that window.
Downloading with dvc pull, fetch, and checkout
dvc pull is two steps in one: dvc fetch downloads missing files from the remote into the local cache, then dvc checkout places them in the workspace. On a new machine the usual routine is:
git clone https://github.com/example/project.git
cd project
dvc pullYou can run the steps separately when that helps:
dvc fetchfills the cache and leaves the workspace untouched. This suits a CI job that downloads everything first and uses it later, or a laptop that prefetches data before you go offline.dvc checkoutlinks cache files into the workspace. It needs no network once the cache is filled.
As with push, you can limit the scope with targets and flags:
dvc pull data/raw.csv.dvc
dvc pull -r backup
dvc fetch -Advc pull with no target pulls everything referenced by the current commit. For a repository with a model, several datasets, and intermediate pipeline outputs, naming the target saves time and disk space.
Checking sync state with dvc status -c
Before you tell a colleague that the data is ready, check it:
dvc status -cThe -c (--cloud) flag compares the local cache with the remote. If they agree, the output says that the cache and the remote are in sync. Otherwise it lists files marked new (in your cache, not on the remote) or deleted/missing (on the remote but not in your cache).
Plain dvc status answers a different question. It compares the workspace with the pointer files and dvc.lock, so it tells you whether you forgot to run dvc add or dvc commit after a change. Run both before a release.
Using more than one remote
A team often wants a fast shared store plus a slower backup, or a read-only public mirror next to a private writable store. Keep both in .dvc/config and name the default for daily work:
dvc remote add -d storage s3://my-bucket/dvc-store
dvc remote add backup gs://my-backup-bucket/dvc-store
dvc push # to storage
dvc push -r backup # to backup
dvc pull -r backup # fallback if storage is unavailableA single dvc push goes to one remote only, so mirroring means running the command twice. Individual .dvc files can also pin a remote with a remote: field in their outs entry. That field is useful for one very large dataset that belongs in different storage, but it makes the project harder to read, so use it sparingly.
Common errors and how to read them
- Pull reports missing files or cache. The pointer file exists in Git but the data was never pushed, or was pushed to a different remote. Ask the author to run
dvc pushfrom that commit. Then checkdvc remote listto confirm you are reading from the remote they wrote to. - No remote configured. The default remote is not set, which happens when
-dwas omitted. Rundvc remote default NAMEor pass-r NAME. - Authentication failures on push or pull. The credentials are visible to Git commands but not to DVC, or they belong to the wrong profile. Test with the cloud provider's own CLI first, using the same environment and profile. If that works, check
.dvc/config.localfor stale values that override your environment. - Pushing succeeds but a collaborator sees old data. The collaborator ran
dvc pullbeforegit pull, so their pointer files were old. Always update Git first. DVC reads whatever pointer files are on disk. - A push uploads nothing and says everything is up to date, yet the data is absent. The data was never added to the cache on your machine, perhaps because you committed a
.dvcfile written by someone else, or you rangit addinstead ofdvc add. Rundvc statusanddvc addagain. - Config contains a secret in Git history. If a key reached
.dvc/configand was committed, rotate the key. Removing the line in a later commit does not remove it from history.
Try it with a local remote
You can practice the whole cycle without a cloud account, because a remote can be any directory. The commands below assume Git is configured with a name and email.
mkdir demo && cd demo
git init
dvc init
git commit -m "Initialize DVC"
mkdir data
seq 1 1000 > data/raw.csv
dvc add data/raw.csv
git add data/raw.csv.dvc data/.gitignore
git commit -m "Track raw data with DVC"
dvc remote add -d storage /tmp/dvc-store-demo
git add .dvc/config
git commit -m "Configure default DVC remote"
dvc status -c
dvc push
dvc status -c
cd ..
git clone demo demo-clone
cd demo-clone
ls data
dvc pull
ls dataBefore the push, dvc status -c shows data/raw.csv as new. After the push it reports the cache and remote in sync. In the clone, the first ls data shows no raw.csv, only the pointer file. After dvc pull the file appears.
Exercises
Exercise
A teammate clones your repository and runs dvc pull, which fails with missing files. Your .dvc files are committed and git push succeeded. Name the most likely cause and the fix, and give one command that would have shown the problem before you shared the commit.
Show answer
The data was never uploaded to the remote (or went to a different remote), so Git has the pointer files but the remote has no matching content. Run dvc push from that commit, using -r if the teammate's default remote differs. Running dvc status -c before sharing would have listed the files as new, meaning present in your cache but not on the remote.
Exercise
Where should you put an S3 secret access key, and where should the bucket URL go? Give the file or flag for each.
Show answer
The URL belongs in .dvc/config, which is committed (set with dvc remote add). The secret key belongs in .dvc/config.local, written with dvc remote modify --local storage secret_access_key ..., or in the environment or the provider's credential file. .dvc/config.local is ignored by Git.
Exercise
You tagged v1.0, pushed data, and then moved to v2.0 where you also ran dvc push. A colleague checks out v1.0 and cannot pull. You only ever ran plain dvc push from v1.0 before you tagged it. What could have gone wrong, and which flag would cover all tags?
Show answer
If the data for v1.0 was not in the cache or workspace when you pushed, or you pushed before the final dvc add for that version, it never reached the remote. A plain dvc push only uploads data for the commit that is checked out. Use dvc push --all-tags (or -A for every commit) from a machine whose cache still holds the older data.