Another solution that may be more consistent and automatable is to leverage pre-commit with nbstripout or nbconvert. This should make a much cleaner git diff.
Personally, I would lean on this one that uses nbconvert. I feel that it could be infuriating to some to find their notebook output gone when doing a git commit, but having it output to html/python would be far less intrusive.
Further searching brought me to this one that appears more popular.
All you need to do is add a
.pre-commit-config.yaml file at the root of your project, then instruct developers to
pip install pre-commit && pre-commit install and it will take care of the rest.