27. How to Use Git with Jupyter Notebooks for Data Projects
27.3 .gitignore for Data Work
Why. Accidental commit of a 900 MB extract or a .env API key is a bad day. .gitignore tells Git what to skip.
What. Common ignores: __pycache__/, .ipynb_checkpoints/, .env, venv/, large data/raw/* (maybe keep a tiny sample), OS junk .DS_Store.
How.
Write .gitignore early
- Create
.gitignorebefore the first big add. - Ignore checkpoints and virtualenvs.
- Ignore secrets files by name.
- Decide: ignore all of
data/raw/or only*.csvlarger patterns. - Keep a small
data/raw/sample_orders.csvtracked if you need CI-free demos.
Worked example A — Starter ignore file.
# Python
__pycache__/
.venv/
venv/
# Jupyter
.ipynb_checkpoints/
# Secrets
.env
.env.*
secrets.json
# Data bulk (keep samples if you want)
data/raw/*.csv
data/raw/*.csv.zip
!data/raw/sample_orders.csv
# Outputs can be rebuilt — optional ignore
# outputs/*.png
Worked example B — Check what Git sees.
git status --short
Worked example C — Un-ignore a sample.
The !data/raw/sample_orders.csv line re-includes one small file after a folder pattern ignore — useful for classmates.
Ravindra Bagale's Tip
Pehle gitignore, mag git add .. Ultke kele ki mote CSV history madhe jail.