Invalid Jupyter notebooks on GitHub

The Problem
When trying to view Jupyter notebooks on GitHub, we sometimes see the above ‘Invalid Notebook’ message. This often happens with notebooks created in Google Colab as it structures notebook metadata differently than what GitHub’s renderer expects.
In this gist I describe different solutions (workarounds) for this issue, including a description of automating a fix as a pre-commit hook.