On , I learnt ...
How to avoid committing Jupyter Notebook output to Git
When working with Jupyter Notebooks, the output of each cell does not need to be committed as:
- It can contain sensitive information
- It makes the diff harder to read
- It can be easily regenerated by re-running the notebook
This can be achieved by adding a Git filter:
git config filter.strip-notebook-output.clean 'jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR'
and enabling it for .ipynb
files using a local .gitattributes
file:
*.ipynb filter=strip-notebook-output
Now git status
will be readable as only the changes to cell contents (and any
new cells) will be tracked.
Advice lifted from this Gist.