Using the Git Plug-in
In JupyterLab, you can use the Git plug-in to clone the GitHub open-source code repository, quickly view and edit data, and submit the modified data.
Prerequisites
The notebook instance is running.
Starting the Git Plug-in of JupyterLab
In the notebook instance list, locate the target instance and click Open in the Operation column to go to the JupyterLab page.
Figure 1 shows the Git plug-in of JupyterLab.
Cloning a GitHub Open-Source Code Repository
Access a GitHub open-source code repository at https://github.com/jupyterlab/extension-examplesitHub. Click , enter the repository address, and click OK to start cloning. After the cloning is complete, the code library folder is displayed in the navigation pane of JupyterLab.
Cloning a GitHub Private Code Repository
When you clone a GitHub private code repository, a dialog box will be displayed, asking you to enter your personal credentials. In this case, enter the personal access token in GitHub.
To obtain a personal access token, perform the following operations:
- Log in to GitHub and open the configuration page.
- Click Developer settings.
- Choose Personal access tokens > Generate new token.
- Verify the account.
- Describe the token, select permissions to access the private repository, and click Generate token to generate a token.
- Copy the generated token to CloudBuild.
- Save the token securely once it is generated. It will be unavailable after you refresh the page. If it is not obtained, generate a new token.
- Enter a valid token description so that it can be easily identified. If the token is deleted by mistake, the building will fail.
- Delete the token when it is no longer used to prevent information leakage.
Viewing a Code Repository
In the list under Name, double-click the folder you want to use and click the Git plug-in icon on the left to access the code repository corresponding to the folder.
By default, the Git plug-in clones the master branch. To switch another branch, click Current Branch to expand all branches and click the target branch name.
Viewing Modifications
If a file in the code repository has been modified, you can view the modified file under Changed on the Changes tab page. Click Diff this file on the right of the file name to view the modifications.
Committing Modifications
After confirming that the modifications are correct, click Stage this change on the right of the file name, which is equivalent to running the git add command. The file enters the Staged state. Enter the message to be committed in the lower left corner and click Commit that is equivalent to running the git commit command.
On the History tab page, view the committing status.
Click the push icon, which is equivalent to running the git push command, to push the code to the GitHub repository. After the pushing is successful, the message "Successfully completed" is displayed. If the token used for OAuth authentication has expired, a dialog box is displayed asking you to enter the user token or account information. Enter the information as prompted. This section describes the authorization using a personal access token. If you use a password for authorization but the password becomes unavailable, perform the operations described in What Do I Do If the Git Plug-in Password Is Invalid?
After the preceding operations are complete, on the History tab page of the JupyterLab Git plug-in page, you can see that origin/HEAD and origin/master point to the latest push. In addition, you can find the corresponding information in the committing records of the GitHub repository.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot