Skip to content

Instantly share code, notes, and snippets.

@kjaanson
Last active April 4, 2024 10:56
Show Gist options
  • Save kjaanson/215f0c7f2c4758397104ee265d4f393d to your computer and use it in GitHub Desktop.
Save kjaanson/215f0c7f2c4758397104ee265d4f393d to your computer and use it in GitHub Desktop.
Useful git hooks for working with Jupyter notebooks/Data analysis
#!/bin/sh
#
# Pre-commit hook for clearing output cells from commited analysis Jupyter notebooks.
#
echo "Running pre-commit hook to clear output from deliver/*.ipynb notebooks."
for notebook in git diff --cached --name-only -- 'deliver/*.ipynb'
do
echo "Clearing output from $notebook"
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --ClearOutputPreprocessor.remove_metadata_fields=[] --to notebook --inplace $notebook
git add $notebook
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment