<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged dvc</title>
<link>https://coderlegion.com/tag/dvc</link>
<description>Powered by Question2Answer</description>
<item>
<title>1minMLOps #2 :Versioning your data with DVC</title>
<link>https://coderlegion.com/17659/1minmlops-2-versioning-your-data-with-dvc</link>
<description>&lt;p&gt;In the last article we talked about why ML is harder than regular software: code, data and environment all move at the same time. Today we're tackling the second one &lt;strong&gt;data&lt;/strong&gt; with a tool called &lt;strong&gt;DVC&lt;/strong&gt; (Data Version Control).&lt;/p&gt;
&lt;h3 id=&quot;why-not-just-use-git-&quot;&gt;Why not just use Git?&lt;/h3&gt;
&lt;p&gt;Git is amazing for code, but it was designed for small text files. The moment you commit a 2 GB CSV or a folder of 50,000 images, things get unpleasant fast: the repo balloons, &lt;code&gt;git clone&lt;/code&gt; becomes a coffee break, and GitHub starts politely asking you to leave.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DVC&lt;/strong&gt; solves this by being &quot;Git for data&quot;: it stores tiny pointer files in your repo and pushes the actual heavy data to a separate storage backend (S3, GCS, an SSH server, even a local folder). You get versioning, branching and reproducibility, without bloating Git.&lt;/p&gt;
&lt;h3 id=&quot;step-1-install-dvc&quot;&gt;Step 1: Install DVC&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;pip install dvc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want S3 support, install the extra:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;pip install &quot;dvc[s3]&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Other backends like &lt;code&gt;gs&lt;/code&gt;, &lt;code&gt;azure&lt;/code&gt;, &lt;code&gt;ssh&lt;/code&gt; work the same way — just swap the extra.&lt;/p&gt;
&lt;h3 id=&quot;step-2-initialize-dvc-in-your-project&quot;&gt;Step 2: Initialize DVC in your project&lt;/h3&gt;
&lt;p&gt;Let's start a tiny project:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mkdir mlops-demo &amp;amp;&amp;amp; cd mlops-demo
git init
dvc init
git commit -m &quot;Initialize DVC&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;dvc init&lt;/code&gt; creates a &lt;code&gt;.dvc/&lt;/code&gt; folder (a bit like &lt;code&gt;.git/&lt;/code&gt;) and a &lt;code&gt;.dvcignore&lt;/code&gt; file. From now on, DVC and Git work side by side.&lt;/p&gt;
&lt;h3 id=&quot;step-3-track-your-first-dataset&quot;&gt;Step 3: Track your first dataset&lt;/h3&gt;
&lt;p&gt;Let's grab a small dataset to play with. We'll use the classic Iris CSV:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mkdir data
curl -L https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv -o data/iris.csv
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note (PowerShell users):&lt;/strong&gt; in PowerShell, &lt;code&gt;curl&lt;/code&gt; is an alias for &lt;code&gt;Invoke-WebRequest&lt;/code&gt;, which doesn't accept the &lt;code&gt;-L&lt;/code&gt; flag and will error with &lt;code&gt;A parameter cannot be found that matches parameter name 'L'&lt;/code&gt;. Use one of these instead:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-powershell&quot;&gt;# Option 1: call the real curl binary (ships with Windows 10+)
curl.exe -L https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv -o data/iris.csv

# Option 2: native PowerShell
Invoke-WebRequest -Uri https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv -OutFile data/iris.csv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;curl.exe&lt;/code&gt; follows redirects by default, so &lt;code&gt;-L&lt;/code&gt; is optional there.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now tell DVC to track it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dvc add data/iris.csv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;DVC will:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Move &lt;code&gt;data/iris.csv&lt;/code&gt; into its cache (&lt;code&gt;.dvc/cache/&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Create a small pointer file &lt;code&gt;data/iris.csv.dvc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;data/iris.csv&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt; automatically&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Commit the &lt;strong&gt;pointer&lt;/strong&gt;, not the data, to Git:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git add data/iris.csv.dvc data/.gitignore
git commit -m &quot;Track iris dataset with DVC&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you peek inside &lt;code&gt;data/iris.csv.dvc&lt;/code&gt;, you'll see something like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;outs:
- md5: 1f8e3c...
  size: 3858
  hash: md5
  path: iris.csv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That hash is the version of your data. Change one byte in the CSV, and the hash changes.&lt;/p&gt;
&lt;h3 id=&quot;step-4-set-up-a-remote-storage&quot;&gt;Step 4: Set up a remote storage&lt;/h3&gt;
&lt;p&gt;Right now, the data only lives on your machine. Let's push it somewhere others (or future-you on another laptop) can pull it from.&lt;/p&gt;
&lt;p&gt;For a quick local test, you can use a folder as a &quot;remote&quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mkdir -p /tmp/dvc-storage
dvc remote add -d localremote /tmp/dvc-storage
git add .dvc/config
git commit -m &quot;Configure DVC remote&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For real projects, swap that with S3 or similar:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dvc remote add -d s3remote s3://my-bucket/dvc-storage
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then push the data:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dvc push
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-5-the-reproducibility-test&quot;&gt;Step 5: The reproducibility test&lt;/h3&gt;
&lt;p&gt;This is the moment that makes DVC click. Let's pretend you're a teammate cloning the repo for the first time:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd /tmp
git clone /path/to/mlops-demo fresh-clone
cd fresh-clone
ls data/
# Only iris.csv.dvc — the actual CSV is missing!

dvc pull
ls data/
# iris.csv is back, byte-for-byte identical
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You just versioned a dataset alongside your code, &lt;strong&gt;without&lt;/strong&gt; committing it to Git. &lt;/p&gt;
&lt;h3 id=&quot;step-6-updating-the-dataset&quot;&gt;Step 6: Updating the dataset&lt;/h3&gt;
&lt;p&gt;Real data changes. Let's simulate that:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo &quot;6.0,3.0,4.5,1.5,versicolor&quot; &amp;gt;&amp;gt; data/iris.csv
dvc add data/iris.csv
git add data/iris.csv.dvc
git commit -m &quot;Add new sample to iris dataset&quot;
dvc push
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The pointer file's hash updated. If you ever need the &lt;em&gt;old&lt;/em&gt; version of the data, just &lt;code&gt;git checkout&lt;/code&gt; an older commit and run &lt;code&gt;dvc pull&lt;/code&gt; , DVC fetches the dataset that matched that commit. Time travel for data.&lt;/p&gt;
&lt;h3 id=&quot;why-this-matters&quot;&gt;Why this matters&lt;/h3&gt;
&lt;p&gt;With this in place, you can finally answer the question &lt;em&gt;&quot;which data produced that model?&quot;&lt;/em&gt; with a Git commit hash. That's a huge upgrade.&lt;/p&gt;
&lt;p&gt;In the next article, we'll add the second piece of the puzzle: &lt;strong&gt;experiment tracking&lt;/strong&gt; with MLflow, so we never again lose track of which hyperparameters and which data produced which metric.&lt;/p&gt;
&lt;p&gt;Stay tuned and have fun! &lt;/p&gt;
&lt;p&gt;
  If you enjoyed this article, you can support my work here:
&lt;/p&gt;
&lt;p&gt;
  &lt;a rel=&quot;nofollow&quot; href=&quot;https://buymeacoffee.com/mohamedarbi&quot; target=&quot;_blank&quot;&gt;
    &lt;img src=&quot;https://cdn.buymeacoffee.com/buttons/default-orange.png&quot; alt=&quot;Buy Me A Coffee&quot; height=&quot;41&quot; width=&quot;174&quot;&gt;
  &lt;/a&gt;
&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/17659/1minmlops-2-versioning-your-data-with-dvc</guid>
<pubDate>Wed, 13 May 2026 00:40:36 +0000</pubDate>
</item>
</channel>
</rss>