Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save avoidik/0a221aa6f4c6d97288bdc4c498ad2d3a to your computer and use it in GitHub Desktop.
Save avoidik/0a221aa6f4c6d97288bdc4c498ad2d3a to your computer and use it in GitHub Desktop.
How to commit jupyter notebooks without output to git while keeping the notebooks outputs intact locally
  1. Add a filter to git config by running the following command in bash inside the repo:
git config filter.strip-notebook-output.clean 'jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR'  

Or

git config --global filter.strip-notebook-output.clean 'docker run --rm -i -v \"${pwd}:/home/jovyan\" jupyter/datascience-notebook jupyter nbconvert --clear-output --to=notebook --stdin --stdout --log-level=ERROR'
  1. Create a .gitattributes file inside the directory with the notebooks

  2. Add the following to that file:

*.ipynb filter=strip-notebook-output  

After that, commit to git as usual. The notebook output will be stripped out in git commits, but it will remain unchanged locally.

This gist is based on @dirkjot's answer to this StackOverflow question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment