GitHub Version Control

This guide describes how to set up version control for notebooks using GitHub.

Using the Databricks CLI and Workspace API

Although this document describes how to set up GitHub integration through the UI, we recommend that you integrate with Git through the Databricks CLI and Workspace API. It is a more powerful tool.

Getting an Access Token

Go to GitHub and create a personal access token that allows access to your repositories:

  1. From GitHub, access the menu on the upper right, next to your Gravitar, and select Settings.

  2. Go to the Personal access tokens tab.

  3. Click the Generate New Token button to create a new token.

  4. Select the repo and public_repo permissions, and click the Generate Token button.


  5. Copy the token to your clipboard. You will enter this token in Databricks in the next step.

See the GitHub documentation to learn more about how to create personal access tokens.

Saving Your Access Token to Databricks

You can save your GitHub personal access token through the Account Settings page. Click the User icon on the top right of your screen and select Account Settings.

  1. Go to the “Git Integration” section.

  2. If you have previously entered credentials, click the “Change token or app password” button.

  3. Paste your token into the Token or app password field, and click Save.


Linking a Notebook to GitHub

In order to link your notebook to a file on GitHub, open the History Panel by clicking Revision History. The Git status bar should display Git: Not linked.


You cannot modify a notebook while the Revision history tab is open. Once you click Git: Not linked, you should see the notebook’s GitHub Preferences. The first time you open your notebook, the option displayed will be Unlink, because the notebook is not on GitHub.

Select Link, and you should be able to edit the integration fields.

  • Copy the URL of the GitHub repository in the Link field.
  • The path in the second text box determines where in the repository you would like to store your file.
  • Python notebooks will have the suggested default file extension .py. If you use .ipynb, your notebook will save in iPython notebook format.
  • If the file already exists on GitHub, you can directly copy and paste the URL of the file.
  • Click Save to finish linking your notebook.
  • A prompt will appear with the option “Save this file to your GitHub repo” if this file did not previously exist.

Save a Notebook to GitHub

While the changes that you make to your notebook are saved automatically to the history list, changes do not automatically persist to GitHub.

  • Click Save Now to save your notebook to GitHub.
  • Optionally, enter a message to describe your change.
  • Make sure that Also Commit to GitHub is selected.


Revert/Update a Notebook to a version from GitHub

Once you link a notebook, Databricks will sync your history with Git every time you re-open the history panel.


Versions that sync to GitHub will have the commit hashes as part of the entry. Click Restore this version to view old/new versions of your notebook from GitHub.

Branch Support

You can work on an arbitrary branch of your repository with Databricks. You can even create new branches inside Databricks.

In order to create a branch:

  1. In the Revision History panel, click the Git Status bar to open the GitHub panel.
  2. Click the Branch dropdown.
  3. Enter your branch name.
  4. Select the Create Branch option at the bottom of the dropdown. The parent branch is indicated. You will always branch from your current selected branch.

Listing Branches


Creating Branches



You can also rebase your branch inside Databricks. The Rebase button displays if new commits are available in the parent branch. Currently we only allow rebasing on top of the default branch of the parent repository.


For example, assume that you are working on databricks/reference-apps. You fork it into your own account (for example, brkyvz) and start working on a branch called my-branch. If a new update gets pushed to databricks:master, then the Rebase button displays, and you will be able to pull the changes into your branch brkyvz:my-branch.

Rebasing works a little differently in Databricks. Assume the following branch structure:


After a rebase, the branch structure will look like:


What’s different here is that Commits C5 and C6 will not apply on top of C4. They will appear as local changes in your notebook. Any merge conflict will show up as follows:


You can then commit to GitHub once again using the Save Now button.

What happens if someone branched off from my branch that I just rebased?

If your branch (for example, branch-a) was the base for another branch (branch-b), and you rebase, you need not worry! Once a user also rebases branch-b, everything will work out. The best practice in this situation is to use separate branches for separate notebooks.

Best Practices for Code Reviews

Databricks supports git branching.

  • You can link a notebook to your own fork and choose a branch.
  • We recommend using separate branches for each notebook.
  • Once you are happy with your changes, you can use the Create PR link in the Git Preferences dialog to take you to GitHub’s Pull Request page.
  • The Create PR link displays only if you’re not working on the default branch of the parent repository.

GitHub Enterprise


Integration with GitHub Enterprise is not officially supported.


If you receive errors related to syncing GitHub history, verify the following:

  1. You have initialized the repository on GitHub, and it isn’t empty. Try the URL that you entered and verify that it forwards to your GitHub repository.
  2. Your personal access token is active.
  3. If the repository is private, you must have at least read level permissions (through GitHub) on the repository.