Chapter 2. Collaborating on notebooks using Git
If your notebooks or other files are stored in Git version control, you can import them from a Git repository onto your notebook server to work with them in JupyterLab. When you are ready, you can push your changes back to the Git repository so that others can review or use your models.
2.1. Uploading an existing notebook file from a Git repository using JupyterLab
You can use the JupyterLab user interface to clone a Git repository into your workspace to continue your work or integrate files from an external project.
Prerequisites
- A launched and running Jupyter server.
- Read access for the Git repository you want to clone.
Procedure
Copy the HTTPS URL for the Git repository.
-
On GitHub, click ⤓ Code
HTTPS and click the Clipboard button. - On GitLab, click Clone and click the Clipboard button under Clone with HTTPS.
-
On GitHub, click ⤓ Code
In the JupyterLab interface, click the Git Clone button ( ).
You can also click Git
Clone a repository in the menu, or click the Git icon ( ) and click the Clone a repository button. The Clone a repo dialog appears.
- Enter the HTTPS URL of the repository that contains your notebook.
- Click CLONE.
- If prompted, enter your username and password for the Git repository.
Verification
- Check that the contents of the repository are visible in the file browser in JupyterLab, or run the ls command in the terminal to verify that the repository is shown as a directory.
2.2. Uploading an existing notebook file from a Git repository using the command line interface
You can use the command line interface to clone a Git repository into your workspace to continue your work or integrate files from an external project.
Prerequisites
- A launched and running Jupyter server.
Procedure
Copy the HTTPS URL for the Git repository.
-
On GitHub, click ⤓ Code
HTTPS and click the Clipboard button. - On GitLab, click Clone and click the Clipboard button under Clone with HTTPS.
-
On GitHub, click ⤓ Code
-
In JupyterLab, click File
New Terminal to open a terminal window. Enter the
git clone
command.git clone <git-clone-URL>
Replace `<git-clone-URL>` with the HTTPS URL, for example:
[1234567890@jupyter-nb-jdoe ~]$ git clone https://github.com/example/myrepo.git Cloning into myrepo... remote: Enumerating objects: 11, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (10/10), done. remote: Total 2821 (delta 1), reused 5 (delta 1), pack-reused 2810 Receiving objects: 100% (2821/2821), 39.17 MiB | 23.89 MiB/s, done. Resolving deltas: 100% (1416/1416), done.
Verification
- Check that the contents of the repository are visible in the file browser in JupyterLab, or run the ls command in the terminal to verify that the repository is shown as a directory.
2.3. Updating your project with changes from a remote Git repository
You can pull changes made by other users into your data science project from a remote Git repository.
Prerequisites
- You have configured the remote Git repository.
- You have already imported the Git repository into JupyterLab, and the contents of the repository are visible in the file browser in JupyterLab.
- You have permissions to pull files from the remote Git repository to your local repository.
- You have credentials for logging in to Jupyter.
- You have a launched and running Jupyter server.
Procedure
- In the JupyterLab interface, click the Git button ( ).
- Click the Pull latest changes button ( ).
Verification
- You can view the changes pulled from the remote repository in the History tab of the Git pane.
2.4. Pushing project changes to a Git repository
To build and deploy your application in a production environment, upload your work to a remote Git repository.
Prerequisites
- You have opened a notebook in the JupyterLab interface.
- You have already added the relevant Git repository to your notebook server.
- You have permission to push changes to the relevant Git repository.
- You have installed the Git version control extension.
Procedure
-
Click File
Save All to save any unsaved changes. - Click the Git icon ( ) to open the Git pane in the JupyterLab interface.
Confirm that your changed files appear under Changed.
If your changed files appear under Untracked, click Git
Simple Staging to enable a simplified Git process. Commit your changes.
- Ensure that all files under Changed have a blue checkmark beside them.
- In the Summary field, enter a brief description of the changes you made.
- Click Commit.
-
Click Git
Push to Remote to push your changes to the remote repository. - When prompted, enter your Git credentials and click OK.
Verification
- Your most recently pushed changes are visible in the remote Git repository.