Working with Git(hub) and python notebook tips

Find yourself using Git/Github and Jupyter notebooks quite a bit? Frustrated that these tools don’t natively support git diff? Here’s two very quick tips to make working with these tools a bit better.

Tip one:

Get Github to show rich diffs of Jupyter Notebook files in pull requests.

With the feature preview enabled, you can compare cell-level inputs and outputs (including images), as well as notebook and cell metadata, thanks to nbdime.

Details.

Steps:

  1. In the upper-right corner of any page, click your profile picture, then click Feature preview.
  2. To view details for a feature, in the left sidebar, click the feature’s name, i.e., Rich Jupyter Notebook Diffs.
  3. To the right of a feature’s name, click Enable.

Tip two:

Tweak git settings on Gadi to use nbdime (also works anywhere but you’ll need to install nbdime yourself)

Add to your .gitconfig file (or the docs suggest it may be simpler to use nbdime config-git --enable --global – untested!)

[diff "jupyternotebook"]
        command = git-nbdiffdriver diff
[merge "jupyternotebook"]
        driver = git-nbmergedriver merge %O %A %B %L %P
        name = jupyter notebook merge driver
[difftool "nbdime"]
        cmd = git-nbdifftool diff \"$LOCAL\" \"$REMOTE\" \"$BASE\"
[mergetool "nbdime"]
        cmd = git-nbmergetool merge \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"

Here’s a use case example:

[gadi-login-06: access-om3-paper-2]$ module purge;module use /g/data/xp65/public/modules;module load conda/analysis3
Loading conda/analysis3-26.03
  Loading requirement: singularity
[1217][gadi-login-06: access-om3-paper-2]$ git diff
nbdiff /scratch/tm70/cyb561/tmp/git-blob-jpE5DP/00_template_notebook.ipynb notebooks/00_template_notebook.ipynb
--- /scratch/tm70/cyb561/tmp/git-blob-jpE5DP/00_template_notebook.ipynb  2026-05-06 10:43:11
+++ notebooks/00_template_notebook.ipynb  2026-05-06 10:42:18
## modified /cells/1/source:
@@ -4,4 +4,6 @@
 papermill = False

 # Set esm_file to the datastore for the main experiment of interest
-esm_file = "/g/data/ol01/outputs/access-om3-25km/MC_25km_jra_iaf+wombatlite-test3v2-00532b88/datastore.json"

+esm_file = "/g/data/ol01/outputs/access-om3-25km/MC_25km_jra_iaf+wombatlite-test3v2-00532b88/datastore.json"
+
+this is a test diff

Note:

  • in the above, the module load conda/analysis3 command makes nbdime available.
1 Like