Set Up Git in JupyterHub

We recommend syncing content to and from JupyterHub using Git and GitHub. However, before you can start, we will need to tell Git and GitHub who we are.

1. Configure Git

First, add your name and email to git config (lines 1 and 2). Also set git to always clone using SSH (line 3). Line 4 sets the default branch name to main instead of the traditionally used master.

git config --global user.name "John Doe" (don't forget the quotes!)
git config --global user.email your_email@example.com
git config --global --add url."git@github.com:".insteadOf "https://github.com/"
git config --global init.defaultBranch main

2. Generate and SSH Key and add it to GitHub

  1. Start a terminal session inside your hub using the terminal launcher (#18 in the Interface Overview)

  2. Generate an ssh key:

    ssh-keygen -t rsa -b 4096

This creates a new ssh key, using the provided email as a label.

> Generating public/private rsa key pair.

3. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location:

> Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

4. You will be asked for a passphrase. If you will be using nbgitpuller magic links in combination with git, please leave ot empty, the passphrase prompt may break nbgitpuller. If you leave it empty, you won't be asked for the passphrase when connecting to GitHub. For more information, see "Working with SSH key passphrases".

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

5. Add your SSH Key. The command below will show the public SSH key on the terminal. Copy the entire key, starting with ssh-rsa and ending with your email.

cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDWtCVS8LyAWQF60RCGSE5/b4egu7NwjIwNlM1pI+x9cqoZSRP2h4qBH9k2f8C+wOcVQ4jxhF1NmpAs/BA6r9tKQFxXXNz/Dx6X+JLl7BQCdd2ptTC+ozWfbO4zEGpVT4Gozxh6P18zO9VMJFxl6FdCwsDYeCJw7ywlY4H7zzvPx3lINplHacqViCwDIo3eQWCwesdIAAd/BIZGOl9FTqepxcAAR5RB5/pNGZbwuoXgnmIicEqu9+WBWaPoSYBwnxTVneMHZkYqVmmGWAN67DC0VICPMXFgAmfRr4SUpG5HP10tMNKNzhOT5zUhvSqWcGvCnShHopfUDO3FNXOvNhRfVl/BCaTEIDQQ/FomQg8yT6aagtejqv6DxH+KYrcsXiDX6eDn/PQMTitdMwApuvteV0/R+NQ0H4rKP1bpy6c/heGUpTTeM2czgkaPLT+gR98IwBMT3W5z0QMIznS7F+HPi2aQmazHZooPuwsunbpNkdPWbiVITRdsvtWI2qgPMrYYQZlPARKWYeg/APCf8ucvDTrFLL+Y59xZZujPCaz/Lp4OpUrvCkJP2esPeoCRgzb8VT9zJRWieAAxNldetUnN06Gh7F9I11WoQcE/BGTCVd4jO2tDu7rI46WlaOtLe8eOmelT+NVabePq3okFq7+KjdIny+8X+YhVjnAiY7VS9w== ccvdemo@CIS2L39BJGH6

6. Go to https://github.com. In the upper-right corner of any page, click your profile photo, then click Settings.

7. In the user settings sidebar, click SSH and GPG keys.

8. Click New SSH key or Add SSH key.

9. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air".

10. Paste your key into the "Key" field.

12. If prompted, confirm your GitHub password.

3. Test your ssh connection:

  1. In the terminal of your hub type

  2. After accepting the host key you should received:

    Hi USERNAME! You've successfully authenticated, but GitHub does not
    > provide shell access.

3. For more information check GitHub's documentation:

https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

Last updated