Using GitHub with Google Colab

Google Colab has convenient Git integration. This will enable you to edit notebooks in Colab and then commit and push changes back to the repository without ever leaving Colab in your browser.

Setting up GitHub access from Colab

In order to access Git repositories, in particular private ones like you are using in this class, you need to all Colab to access the repositories. To set this up, make sure you are logged in to your Caltech G-Suite. Then, follow the steps below.

  1. Go to the main Google Colab page. You will get a splash page that looks like this.

Google Colab splash page

Click on the “GitHub” tab of the orange bar.

  1. Click the checkbox for including private repos.

  2. An authorization window from GitHub will pop up. (Make sure you are not blocking pop-up windows.) You should authorize Colab to access the bebi103 organization and your repositories.

  3. Under where it says “Enter a GitHub URL or search by organization or user,” search for your team’s repository name, such as 06-bebi103a-2020 if you are on team 6. Underneath the search bar, you will have a pulldown menu of available notebooks. Select the one you want to work on.

Pushing your notebook to the repository

After you have made changes to your notebook, you can commit and push them to the repository. To do so from within a Colab notebook, click FileSave a copy in GitHub. You will be prompted to add a commit message, and after you click OK, the notebook will be pushed to your repository.

Chrome plug-in for quick access

If you use Chrome as your browser, there is a convenient plug-in called Open in Colab that allows you to open a notebook from any GitHub page in Colab. So, after installing the plugin, if you are on the webpage of your team’s repository, you can click the icon next to the address bar in your Chrome browser and the notebook will open in Colab. You can then proceed to push the notebook back to the repository after making your changes as described above.