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
Create .gitignore first and only then run git add ., because if you do it the other way round, a large CSV or a .env file can get stuck in Git history. If a password or API key was ever committed, change (rotate) it at once, because deleting the file later is not enough.
Ravindra Bagale's Tip – मराठी
आधी .gitignore बनवा आणि त्यानंतरच git add . चालवा, कारण उलट्या क्रमाने केलं तर मोठी CSV किंवा .env file Git history मध्ये अडकून बसू शकते. एखादा password किंवा API key कधी commit झाली असेल तर ती लगेच बदला (rotate करा), कारण नंतर file काढून टाकणं पुरेसं नाही.
Ravindra Bagale's Tip – हिंदी
पहले .gitignore बनाओ और उसके बाद ही git add . चलाओ, क्योंकि उल्टे क्रम में करने पर बड़ी CSV या .env file Git history में फँस सकती है। अगर कोई password या API key कभी commit हो गई हो, तो उसे तुरंत बदलो (rotate करो), क्योंकि बाद में file हटाना काफ़ी नहीं है।