Git is a popular version-control and collaboration system for software and is fully supported by Hub Workspace with a Graphical Interface to easily perform the common git operations.
Before you can start using any cloud git solutions like GitLab or GitHub, you would need to authenticate yourself via SSH. In this guide, we will use GitHub as an example but the process would be similar for other providers like BitBucket and GitLab.
- The first step is ofcourse starting and opening up the Workspace.
- Now launch a terminal and run the following command. Make sure to replace your email in the command.
ssh-keygen -t ed25519 -C "email@example.com"
- It will ask a few questions, continue to press the
Returnkey on the keyboard to keep all of the defaults. (DO NOT change the default save path of the key).
- Now run the following command to view the public-key of the key-pair that was generated just now.
- Copy the output of the above command. We need to add this public key to our GitHub account.
- Login to your GitHub account in the browser and go to your settings by clicking on your profile on the top-right.
- On the left, you should see a tab for
SSH and GPG Keysand click on it.
- You should see a green button called
Add New SSH Key. Click on it and paste the public key you just copied earlier and add it.
That's it, you are now authenticated with your GitHub account on the Workspace.
After the authentication, don't stop the workspace immediately, please wait for atleast 5 minutes before stopping the workspace. You can continue doing your work though. This is to ensure your SSH keys are backed up in your persistent storage. This will ensure you remain authenticated across workspace sessions.
Now that you are authenticated with your GitHub account, you can start by cloning your repositories via the SSH URL which is usually of the following format:
The Git GUI app is available as the third tab on the left.
Some Git operations are available on the Git Menu in the Menu bar on the top as well.
You can perform different operations like initializing a git repository, cloning a repository, staging and committing changes, pushing and pulling commits and more in this tab.
- As a simple demo, you can create a new repository in GitHub. Once you create the repository, you can copy the SSH clone URL as shown below.
- Now open the Git Tab in JupyterLab Workspace and click on the
Clone a Repositorybutton.
- Once the repo is cloned, you should see your repo cloned and the folder should appear in the file manager. Now go to the file manager and open your repository folder.
- For demo purposes, you can create a new python file and write some hello world code in it as shown below.
- While being in the repository's folder in the file manager, go to the Git tab. You should see your staging area.
You can press the
+button on the untracked or changed area (depending on whether they are new files or modified files). After pressing that button you should see your changes move to staged area.
- Now you can write a commit message and maybe a description and press the commit button. If you are committing for the first time, it might ask you your github username and email.
- After committing, you can push your changes using the upload cloud icon button (red circle 1). In general, you can pull remote changes using the download cloud icon button (red circle 2).
So this was a basic example of using the Git GUI in the Workspace. Many other basic operations are supported in the GUI. If you want to use advanced git commands, you can use the terminal as you would normally.