r/IPython • • Oct 02 '15

How to use git with iPython notebooks

I love the interactive and flexible environments of iPython. But I hate it I seem unable to get effective version control in using git. executing a cell already results in a diff :(

Anyone using git with iPython notebooks and if so, how do you use it and is it efficient?

13 Upvotes

5 comments sorted by

View all comments

3

u/my_name_is_jody Oct 02 '15

There are several stack overflow answers on the topic. I've also found some good info in other places. I'll try to dig them up later when I'm not on mobile, bit the gist is you can setup a git filter to fix parts of the metadata that shouldn't change from commit to commit. You can also set it up to strip out the run count and output. Finally, for code review sanity, you can get ipython/Jupyter to export the notebook as a script as well. This way, when you look at the different, you can read the python script version, but you can also still access the notebook. I'll see if I can find the links later tonight.

3

u/my_name_is_jody Oct 03 '15

The first two answers here illustrate what I was saying pretty well. http://stackoverflow.com/questions/18734739/using-ipython-notebooks-under-version-control

It should be noted the --script option was removed. You can simulate that same function using the examples here: http://jupyter-notebook.readthedocs.org/en/latest/extending/savehooks.html

Here is what seems to be a fairly recently maintained github project to do this. https://github.com/kynan/nbstripout

If you're on an older version (<3.0) version of ipython/jupyter, this script worked for me as well - https://gist.github.com/pbugnion/ea2797393033b54674af

Good luck. Let us know how it goes.