Workable jupyter notebooks with Git
It is well known that putting Jupyter notebooks into VCS sucks. They almost always result in huge, hard to read diffs and commiting the outputs of computations can quickly eat up your storage.
The following configuration has mostly resolved these problems for me. uvx automatically downloads and installs the required tooling. jupytext converts the notebook to a diffable text format and nbstripout ensures that cell output does not end up commited to VCS.
[diff "jupytext"]
textconv = uvx jupytext --to py:percent --output -
[filter "nbstripout"]
clean = uvx nbstripout
smudge = catI then enable these filters for notebook files using the following setting in my project .gitattributes.
*.ipynb diff=jupytext filter=nbstripout