Overview
Teaching: 15 min
Exercises: 0 minQuestions
- How can notebooks interact with version control?
- How can we compare and merge notebooks using Git?
Jupyter Notebooks are stored in JSON format, which doesn’t play nicely with Git, but several packages and JupyterLab extensions have been developed to make it easier:
git diff
and git merge
shell commands can use nbdime’s diff
and merge for notebook files, but leave Git’s behavior unchanged
for non-notebook files.All three extensions can be used from within the JupyterLab interface.
Installing extensions: Is the git interface not showing up?
JupyterLab is modular, and some parts need to be installed as extensions. In general, either copy and paste installation and configuration commands into a shell or use the JupyterLab extension manager. See the installation instructions.
There are two modes of extension: backend (for the Python server) and frontend (for the browser).
Instructor demonstrates nbdime
- To understand the problem, the instructor first shows the example notebook and then the source code in JSON format.
- Then we introduce a simple change to the example notebook, for instance changing colors and also changing dimensions in
fig.set_size_inches(6.0, 6.0)
.- We save the change and in the JupyterLab terminal try “normal”
git diff
and see that this is not very useful.- Then the instructor installs
jupyterlab-git
which also installsnbdime
.- We then inspect the same change we did in the Git tab of the JupyterLab sidebar.
- If there is time, we can also show nbdime on the command line.
- We can point out that Git can be configured to always use nbdime for notebooks.