Skip to content

Instantly share code, notes, and snippets.

@bobpace
Created March 12, 2021 17:24
Show Gist options
  • Save bobpace/489bd285cf6e2a8b5709c15b807c9524 to your computer and use it in GitHub Desktop.
Save bobpace/489bd285cf6e2a8b5709c15b807c9524 to your computer and use it in GitHub Desktop.
git pre-commit hook to clear jupyter notebooks
#!/bin/bash
notebook_files=$(git diff --cached --name-only | grep -E '\.ipynb$')
if [ -n "$notebook_files" ]
then
source ./notebook/venv/bin/activate || exit
for file in $notebook_files
do
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace "$file"
git add "$file"
done
deactivate
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment