OCI Data Science is adding the Git extension inside the JupyterLab Notebook. This feature allows customers to easily use Git to version control their code in the notebook session.
Git is a version control system that allows you to track changes made to a set of files and allows you to revert to previous version of the files as needed. It is important to version control your code so you can keep track of the changes you have made as you work through your data science project. By using a version control system, teams can collaborate together by having a repository of files that team members can contribute to and add in their changes through merge requests.
The Git extension is a user-friend add-on for JupyterLab that allows users to do basic git actions with a point-and-click interface. It works with cloud-based hosting services such as GitHub and GitLab which let you manage repositories of files you want to keep track of. You can access the Git extension by logging into the JupyterLab Notebook and clicking on the Git icon on the left-hand side of the Notebook. Also, you will see the “Git” tab. If you do not see them, you might be using a notebook with an older image. You can deactivate and reactivate your notebook session in order to access the Git extension.
Let's go through how you can create a new local git repository and commit files to the repository and clone a remote repository.
When you use Git for the first time in the Notebook session, you need to go through some configuration steps. Here are the steps to configure Git and authenticate a GitHub account:
In the terminal, you can enter your Git username and email associated with your Git account with the command below in the terminal.
$ git config --global user.name "Jane Smith"
$ git config --global user.email email@example.com
You can check your settings at any time with the command below:
$ git config --list
You need to set up ssh key for authentication to the Git website. If you do not already have a ssh key you can use, you need to generate a one. Go to the terminal and paste the command below, substituting the email with your GitHub user email
$ ssh-keygen -t ed25519 -C "firstname.lastname@example.org"
You will see a screen like this below
You can press “Enter” to accept the default location of where to save the key.
In the next step, you will be prompted to enter a secure passphrase.
Then, you will need to add your SSH key to the ssh-agent
Type the following command in the terminal
$ eval "$(ssh-agent -s)"
Then you can add your SSH private key to your ssh-agent with the command below. If you had created your key with a different name or used an existing key, replace id_ed25519 in the command below with your private key file.
$ ssh-add -K ~/.ssh/id_ed25519
Next, display the contents of the id_ed25519.pub file
$ cat ~/.ssh/id_ed25519.pub
Copy the content to your clipboard. You will add it in your Github account.
Go to your GitHub account and click on your Avatar. Go to Settings
Then Click “SSH and GPG keys” on the left panel and then click “New SSH key” on the top
You will be able to paste in your SSH key from your terminal in here.
For more information about the process of setting up your ssh keys for authentication to a GitHub account, you can visit https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account. For information about authentication to a GitLab account, you can visit https://docs.gitlab.com/ee/ssh/index.html#add-an-ssh-key-to-your-gitlab-account
Creating a new local Git Repository
Put all the files you want to associate with this new repository in the folder
Move into your folder by double-clicking on it. Then, click on the Git tab and select Initialize a Repository, as shown here:
Now, your local repository has been created and you can start committing files to the repository.
Committing files to the repository
Adding files to your repository is important as you make changes to your files. Let's walk you through how we can commit changes to the repository:
A screen will pop up for you to add a remote repository
Cloning a Repository
If you want to clone a repository from your GitHub account to your notebook, you can follow these steps
You can verify you have cloned your repository.
You can read more about JupyterLab Git Extension in the documentation here https://github.com/jupyterlab/jupyterlab-git