Git repositories in notebooks

Examples related to using Git repositories in your notebook environments with the Workbench CLI.

Prior reading: Overview of the Command Line Interface

Purpose: This document provides summary examples of commands that may be used alone or in combination when using Git repositories in notebook environments.



Git repositories and workspaces

Verily Workbench supports a referenced resource for git repositories. You can add relevant repositories to a given workspace. Then, when you create a cloud environment in that workspace, the referenced repositories are automatically cloned to the cloud environment. You can then use the Git extensions on the cloud environment to commit and push your changes as described in Git integrations with cloud environments. On your local machine, you can use terra git clone --all to clone all the git repository references corresponding to a particular workspace to your preferred directory.

Prerequisites

These instructions assume that you have already installed the Workbench CLI, or are working in a cloud environment where it has been installed, and that you have logged in and identified the workspace you want to work with as described in the Basic Usage Examples.

(Optional) Set up your SSH key

If you want to access private git repositories, then you will first need to associate your Workbench SSH public key with your GitHub account as described in Git integrations with cloud environments.

Add a Git repository to a workspace

Use this command to create a couple of Git repository references.

terra resource add-ref git-repo --name="repo_1" --repo-url=https://github.com/MyGithubOrg/my-public-project.git
terra resource add-ref git-repo --name="repo_2" --repo-url=git@github.com:MyGithubOrg/my-private-project.git

ℹ️ terra resource add-ref

Note that we show two different command examples; one for a public repository (with the https:// construction) and one for a private repository (with the git@ construction). As noted above, private repositories require an SSH key to be set up.

Create a notebook environment pre-loaded with the repositories

Create a cloud environment

Use this command to create a new cloud environment with the desired name. Make sure to replace my-cloud-env with the name you want to use (must be in double quotes).

terra resource create gcp-notebook --name="my-cloud-env"

ℹ️ terra resource create

Get the cloud environment proxy url and connect to the JupyterLab server

This command prints out descriptive information about the given cloud environment, including the “Proxy URL”, which is the link to access the environment’s JupyterLab server.

terra resource describe –-name="my-cloud-env"

ℹ️ terra resource describe

For any repo references that you have added prior to creating a cloud environment, the git repository will be automatically cloned to the JupyerLab server’s file system, under the ~/repos directory.

Referenced repos are automatically cloned to the JupyterLab server's file system.

Clone Git repositories after environment creation

If more git-repo resources are subsequently added to the workspace and you want to clone them into a cloud environment that you have already created (e.g. my-cloud-env), you can run the following command in your notebook.

terra git clone --all

ℹ️ terra git

Last Modified: 16 November 2023