Git and GitHub for ML Projects
You already know Git from the Git course. In an ML repository the same tool faces new visitors: 4 GB CSV files, 300 MB model files, notebooks with giant outputs, and database passwords in .env files. Push the wrong one and the repository becomes slow forever — or leaks a secret.
The rule
Git keeps what people write; big files and secrets stay out.
Sort every file in the churn repository into three boxes:
| Box | Examples | Where it goes |
|---|---|---|
| Written by people, small, text | train.py, features.py, params.yaml, requirements.txt, dvc.yaml, tests |
Git |
| Generated or large | subscriptions.csv, model.pkl, plots |
DVC or a model registry, with a small pointer in Git |
| Secret | .env, cloud keys |
Neither: a secret store, and listed in .gitignore |
Why not just commit the CSV? Git stores every version of every file forever. Ten monthly snapshots of a 4 GB file make a 40 GB repository that every clone downloads. Git is also built to diff text, and a model binary has no useful diff.
Two ML-specific habits come on top:
- Tag the model with its commit. When the model is trained, save the Git commit hash with it (the experiment tracker does this automatically). Then any model can be traced to the exact code.
- Review changes in pull requests on GitHub. A change to
features.pyorparams.yamlchanges the model, so it deserves the same review — and the same automatic checks — as any code change. Protectmainso nothing reaches it without a passing pull request.
Secrets need extra care: deleting a committed password in a later commit does not remove it from history. Treat any committed secret as leaked and rotate it.