="http://www.w3.org/2000/svg" viewBox="0 0 512 512">

4 Using Git for Course Development

As described in the previous chapter about connecting to git, which is a great way to push notebooks, code, and content to students, it is also possible to set up git as a personal development repository for JupyterLab projects or for sharing them with other persons.

4.1 – Git Setup

What you will need:

  • A git repository hosted on a server, such as the ETH-internal GitLab or the public GitHub.
  • The link to the repository you want to use.

The easiest way to setup a git repository is by using the Jupyter builtin tools. Within the Jupyter environment you can switch to the git view:

If you haven’t connected to any git repository before you’ll have the opportunity to Clone a Repository. This will bring up a input field for the git repository URL, which is provided by your git hoster (e.g. https://gitlab.ethz.ch/username/jupyter-notebooks.git).

After entering your credentials you will see a new folder in JupyterLab which is now connected to the corresponding git repository. Within the git view it is possible to commit locally and push/pull to the remote repository.

Difference to nbgitpuller

If you use nbgitpuller, a specified git repository will be pulled into each student directory every time the students access JupyterLab. There is no possibility to push any changes back to the remote repository, as this is usually not wanted.

With a direct git repository setup, every person who connects to the repository will be able to push and pull any changes to the remote location, and all changes are shared among all users.

4.2 – Using SSH

If you start using an SSH connection to your remote repository, you don’t have to type in user name and password every time a sync is performed. To set up an SSH connection, a few steps have to be followed:

  1. Open a terminal within Jupyter:
  2. Execute the following command to generate an ssh key within this JupyterLab:
    ssh-keygen -t rsa -N "" -f "$HOME/.ssh/id_rsa"
  3. Show the key inside the console with the following command:
    cat "$HOME/.ssh/id_rsa.pub"
  4. Now copy the whole output of the command and insert it as a new ssh key in your git profile. Usually this can be found under Edit Profile -> SSH Keys.
  5. Go back to the terminal and switch into your git project directory with:
    cd mydirectory (e.g. cd jupyter-notebooks)
  6. As a last step switch the remote repository from HTTPS to SSH:
    git remote set-url origin your_ssh_git_url
    (e.g. git remote set-url origin git@gitlab.ethz.ch:username/jupyter-notebooks.git)
  7. Accept the repository fingerprint by initiating a first git push and accept by yes. This has to be done only once from the command line.
    git push

If all steps runned sucessfully the push and pull functionality will work now by using an SSH connection and no credentials have to be entered anymore.

The following Jupyter Notebook can be used to help setting up a correct SSH connection to you repository. Just download the file ssh_connect_git.ipynb, add it to your JupyterLab and execute the different cells by pressing Shift + Enter.

For more details please refer to online resources (e.g. Managing Remote Repositories, Adding SSH Key) or contact us at jupyterhub@ethz.ch.

License

Computational Competencies: Using JupyterHub with Moodle Copyright © by LET ETH Zürich. All Rights Reserved.

}