Sync with a remote Git repository

The article describes how you can use common Git capabilities to sync Databricks Repos with a remote Git repository.

To update notebooks and other files in Databricks Repos, you can:

  • Pull changes from the remote Git repo.

  • Resolve merge conflicts.

  • Commit and push from Databricks to the remote repo.

You can also create a new branch in Databricks Repos.

To sync with Git, use the Git dialog. The Git dialog lets you pull changes from your remote Git repository and push and commit changes. You can also change the branch you are working on or create a new branch.

Important

Git operations that pull in upstream changes clear the notebook state. For more information, see Incoming changes clear the notebook state.

Open the Git dialog

You can access the Git dialog from a notebook or from the Databricks Repos browser.

  • From a notebook, click the button at the top left of the notebook that identifies the current Git branch.

    Git dialog button on notebook
  • From the Databricks Repos browser, click the button to the right of the repo name:

    Git dialog button in repo browser

    You can also click the down arrow next to the repo name, and select Git… from the menu.

    Repos menu 2

Pull changes from the remote Git repository

To pull changes from the remote Git repository, click Pullin the Git dialog. Notebooks and other files are updated automatically to the latest version in your remote repository.

Resolve merge conflicts

To resolve a merge conflict, you must either discard conflicting changes or commit your changes to a new branch and then merge them into the original feature branch using a pull request.

  1. If there is a merge conflict, the Repos UI shows a notice allowing you to cancel the pull or resolve the conflict. If you select Resolve conflict using PR, a dialog appears that lets you create a new branch and commit your changes to it.

    resolve conflict dialog
  2. When you click Commit to new branch, a notice appears with a link: Create a pull request to resolve merge conflicts. Click the link to open your Git provider.

    merge conflict create PR message
  3. In your Git provider, create the PR, resolve the conflicts, and merge the new branch into the original branch.

  4. Return to the Repos UI. Use the Git dialog to pull changes from the Git repository to the original branch.

Commit and push changes to the remote Git repository

When you have added new notebooks or files, or made changes to existing notebooks or files, the Git dialog highlights the changes.

git dialog

Add a required Summary of the changes, and click Commit & Push to push these changes to the remote Git repository.

If you don’t have permission to commit to the default branch, such as main, create a new branch and use your Git provider interface to create a pull request (PR) to merge it into the default branch.

Note

  • Results are not included with a notebook commit. All results are cleared before the commit is made.

  • For instructions on resolving merge conflicts, see Resolve merge conflicts.

Create a new branch

You can create a new branch based on an existing branch from the Git dialog:

Git dialog new branch