Bitbucket Version Control for Jupyter Notebooks¶
To use the version control for Jupyter Notebooks using Bitbucket, you must perform the following tasks:
After configuring the Bitbucket Repository, you can perform the following tasks to manage the Jupyter notebook versions:
- Pushing Commits to Bitbucket
- Viewing and Comparing the Jupyter Notebook Versions
- Restoring a Commit from Bitbucket
- Creating a Pull Request from Jupyter Notebooks
- Resolving Conflicts While Using Bitbucket
Configuring Bitbucket¶
You can configure Bitbucket for Jupyter notebooks at per user and per account setting level from the My Accounts or JupyterLab interface.
To configure Bitbucket for Jupyter notebooks at your account level, see Configuring Bitbucket.
To configure Bitbucket from Jupyter notebooks, perform the following steps:
Navigate to Notebooks >> Jupyter and open a Jupyter notebook.
From the left side bar, click on the icon for the Bitbucket versions as shown in the following figure.
Click Configure now.
In the dialog box, add the Bitbucket credentials and click Save. You can either use your Bitbucket credentials or Bitbucket App password.
Bitbucket is now configured for your account.
Linking Jupyter Notebooks to Bitbucket¶
After configuring Bitbucket, you can link the Jupyter notebooks to Bitbucket.
Navigate to the Bitbucket profile and copy the URL from the browser’s address-bar.
Navigate to Notebooks >> Jupyter and open a Jupyter notebook.
From the left side bar, click on the Bitbucket Versions icon as shown in the following figure.
Click the Link Now option.
In the Link Notebook to Bitbucket dialog box, perform the following actions:
Add the Bitbucket repository URL in the Repository Web URL text field. Ensure that the Bitbucket profile has read permissions for the repository to checkout a commit and write permissions for the repository to push a commit.
Select a branch from the Branch drop-down list.
Add an object path file in the Object Path text field.
If you want to strip the outputs from the notebooks before committing to Bitbucket, select the Strip Output checkbox.
A sample is as shown in the following figure.
Click Save.
Pushing Commits to Bitbucket¶
After you link notebooks with Bitbucket, you can start using the notebook to push commits to Bitbucket directly from a notebook.
Steps¶
Open the required Jupyter notebook and save the changes.
From the left side bar, click on the BitBucket Versions icon.
Click the Push icon to commit. A dialog opens to push commits. The following figure shows the version details and the Push to Bitbucket dialog.
Add a commit message and click Save to push the commit to the Bitbucket repository. You can use the option force commit to force push over the old commit (irrespective of any conflict).
Note
Qubole does not store commits or revisions of notebooks. However, commits or revisions of notebooks can be fetched from users’ Bitbucket account whenever required.
Viewing and Comparing the Jupyter Notebook Versions¶
You can view a particular version of the Jupyter notebook by using the View option in the BITBUCKET VERSIONS sidebar as shown below.
You can compare a version of the Jupyter notebook with the previous version or version with current changes by using the Compare option in the BITBUCKET VERSIONS sidebar as shown below.
The Compare icon on top of the left sidebar compares the current notebook with the head of the branch. The Compare hyperlink in the left sidebar compares the given version with the previous version.
The following image shows a sample comparison of Jupyter notebook versions.
Restoring a Commit from Bitbucket¶
- Open the required Jupyter notebook.
- From the left side bar, click on the BitBucket Versions icon.
- Select a version from the list and click Restore to checkout that version.
- Click OK to checkout that version in the confirmation dialog box.
Note
Qubole does not store commits or revisions of notebooks. However, commits or revisions of notebooks can be fetched from users’ Bitbucket account whenever required.
Creating a Pull Request from Jupyter Notebooks¶
Open the required Jupyter notebook.
From the left side bar, click on the BitBucket Versions icon.
Click on the Gear icon in the BITBUCKET VERSIONS pane. The Link Notebook to Bitbucket dialog is displayed.
Click on the Create PR hyperlink.
Proceed with the steps in BitBucket to create the PR.
For more information, see BitBucket Documentation.
Resolving Conflicts While Using Bitbucket¶
There may be conflicts while pushing/checking out commits in the Bitbucket versions.
Note
You can use the option force commit to force push over the old commit (irrespective of any conflict).
Perform the following steps to resolve conflicts in commits:
- Clone the notebook.
- Link the cloned notebook to the same Bitbucket repo branch and path as the original notebook.
- Checkout the latest version of the cloned notebook.
- Manually port changes from the original notebook to the cloned notebook.
- You can commit the cloned notebook after porting changes.