Git was built to track the Linux kernel: thousands of small text files that change a few lines at a time. Data work is pretty much the opposite. Notebooks are JSON with base64 images stuffed inside, and the dataset sitting next to them is 400MB. And somewhere around cell 14 there's a print(client.api_key) you meant to delete.
You can still use git for all of it. It just needs a few settings that never come up when your repo is a web app.
Strip outputs before they're committed
Most of a notebook diff is noise. The execution counts went up and a plot re-rendered to slightly different bytes. Sometimes a 2MB DataFrame preview comes along for the ride. nbstripout removes outputs on the way into git and leaves your working copy alone:
pip install nbstripout
nbstripout --install
That registers a git filter for .ipynb files in this repo. The notebook on your disk keeps its outputs. The copy in git doesn't.
To share it with your team, run nbstripout --install --attributes .gitattributes and commit the .gitattributes file. Everyone still has to run the install once, because the filter itself lives in each person's git config, and git config doesn't travel with the repo.
I like this one because it fixes a second problem for free. If outputs never get committed, a key you printed in an output cell never gets committed either.
Some teams want outputs in the repo so reviewers can see the plot without running anything. If that sounds like you, skip the filter and take the secrets section further down more seriously.
Diff notebooks by cell
Even with outputs gone, git diff on a notebook is still a JSON diff, and nobody wants to review those. nbdime teaches git to diff and merge notebooks cell by cell:
pip install nbdime
nbdime config-git --enable
Now git diff shows changed cells as code and Markdown, and nbdiff-web opens a side-by-side view in your browser.
It also installs a merge driver, and that's the magic part. Without one, a notebook merge conflict drops conflict markers into the middle of the JSON, and the notebook won't open until you fix it by hand.
Put large files in LFS
Commit a 400MB file straight to git and it's in every clone forever, even after you delete it. Git never forgets. That's usually the whole point. Git LFS stores big files on the server and keeps a small pointer in the repo:
git lfs install
git lfs track "*.parquet" "*.pt" "*.onnx"
git add .gitattributes
Set up the patterns before you add the files. Anything committed before the pattern existed stays in normal history, and getting it out means a painful and error prone history re-write.
Raw training data that changes all the time usually doesn't belong in git at all, LFS or not. I'd put it in a storage bucket with versioned paths, or use a tool built for it like DVC. LFS is a good fit for model weights, fixtures and smaller reference datasets.
Keep keys out, and find the ones that got in
Start by keeping the key out of every file git can see. Read it from the environment:
import os
api_key = os.environ["OPENAI_API_KEY"]
Put the .env file you load it from in .gitignore. Then add a backstop: a pre-commit check that blocks any commit containing something that looks like a key. gitleaks works well through the pre-commit framework:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.24.2 # run `pre-commit autoupdate` for the latest
hooks:
- id: gitleaks
Run pre-commit install once per clone. Same deal as nbstripout: hooks don't travel with the repo, so everyone sets it up once.
If you think a key already made it into history, git's pickaxe search finds every commit that added or removed a string:
git log -p -S "sk-" --all
If that turns something up, rotate the key. Do it first, before you touch history. Anyone who cloned before you clean up still has the old key, and so does every fork, so assume it's out. Rewriting history afterwards is fine if you want the repo tidy, and I walked through the options back in 2021. It just doesn't take the key back.
Where Git Revenge fits
Yes, this is the plug. I maintain Git Revenge, a free desktop git client, and I've spent time making data files readable in it.
Open any file and switch to the Rendered view. A notebook shows its Markdown formatted and each code cell with whatever output it stored: text, plots as images, errors with their tracebacks, DataFrames as tables. None of the code runs. (If you set up nbstripout earlier, there won't be stored outputs to show. You still get the code and Markdown, which beats reading JSON.)
CSV and TSV files open as a table you can sort by any column. JSON, YAML and TOML become a tree you can expand and search. Saved plots and other images compare side by side between versions, which is handy when someone says the new loss curve "looks about the same." PDFs, LaTeX and Mermaid render too.
It helps with the setup above as well. The LFS panel lists tracked patterns, lets you add one, and shows which files are downloaded and which are still pointers. Ignoring a file is a right-click, and you pick the scope: just this file, every file with that extension, or only on this machine. There's also a checker that tells you which rule is hiding a path, so "why isn't my .env showing up?" takes a few seconds instead of a trip through every .gitignore in the tree.
When an experiment branch goes sideways, Ctrl+Z undoes the commit, reset, merge or rebase.
It runs your installed git, so nbstripout's filter, nbdime's driver and your gitleaks hook all still apply. The previews stay offline, too. If a notebook points at an image on the web, the preview shows the link and doesn't fetch it.
Where you'll still want the other tools
The rendered view shows one version at a time. That works for reading a notebook as of some commit. For a cell-by-cell comparison between two versions, use nbdime.
It doesn't scan for secrets. That's the gitleaks hook's job.
On a remote GPU box over SSH, you've got the terminal and that's it. It's a desktop app. Push from there and look from your laptop.
You'll need git 2.40 or newer, plus git-lfs for the LFS panel. The previews guide lists every file type it renders, and installers for Windows, macOS and Linux are on the releases page.
Whatever you end up reading it with, set up the filter and the hook first. They're what keep cell 14 out of your history.






