Skip to content

Instantly share code, notes, and snippets.

@ryanbehdad
Last active January 16, 2025 04:41
Show Gist options
  • Save ryanbehdad/f72d2e82134df15704ef38aa875c19d8 to your computer and use it in GitHub Desktop.
Save ryanbehdad/f72d2e82134df15704ef38aa875c19d8 to your computer and use it in GitHub Desktop.
nbstripout

Using nbstripout to Clean Outputs of Jupyter Notebooks before Commits

To improve version control for Jupyter notebooks, consider using nbstripout. This tool automatically removes output cells from notebooks before committing them to Git.

Benefits

  • Cleaner Version History: Eliminates unnecessary output data, making diffs more readable.
  • Reduced Repository Size: Keeps the repository lightweight by excluding bulky output files.
  • Consistent Results: Ensures that notebooks run consistently across different environments.

Installation and Configuration Steps

Install nbstripout

You can install nbstripout using either pip or conda:

pip install nbstripout

or

conda install nbstripout

Enable nbstripout in Your Repository

Navigate to your local repository directory and execute:

nbstripout --install

This command sets up a Git filter that automatically strips output from notebooks upon committing.

Verify the Configuration

To confirm that nbstripout is active, run:

nbstripout --status

Additional Resources

For more information and advanced configuration options, refer to the official nbstripout repository: https://github.com/kynan/nbstripout

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