w.repos: Repos

class databricks.sdk.service.workspace.ReposAPI

The Repos API allows users to manage their git repos. Users can use the API to access all repos that they have manage permissions on.

Databricks Repos is a visual Git client in Databricks. It supports common Git operations such a cloning a repository, committing and pushing, pulling, branch management, and visual comparison of diffs when committing.

Within Repos you can develop code in notebooks or other files and follow data science and engineering code development best practices using Git for version control, collaboration, and CI/CD.

create(url: str, provider: str [, path: Optional[str], sparse_checkout: Optional[SparseCheckout]]) CreateRepoResponse

Usage:

import time

from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

root = f"sdk-{time.time_ns()}"

ri = w.repos.create(
    path=root,
    url="https://github.com/shreyas-goenka/empty-repo.git",
    provider="github",
)

# cleanup
w.repos.delete(repo_id=ri.id)

Creates a repo in the workspace and links it to the remote Git repo specified. Note that repos created programmatically must be linked to a remote Git repo, unlike repos created in the browser.

Parameters:
  • url – str URL of the Git repository to be linked.

  • provider – str Git provider. This field is case-insensitive. The available Git providers are gitHub, bitbucketCloud, gitLab, azureDevOpsServices (Azure DevOps Services, including Microsoft Entra ID authentication), gitHubEnterprise, bitbucketServer (Bitbucket Data Center), gitLabEnterpriseEdition (GitLab Self-Managed), and awsCodeCommit (deprecated by AWS, not accepting new customers).

  • path – str (optional) Desired path for the repo in the workspace. Almost any path in the workspace can be chosen. If repo is created in /Repos, path must be in the format /Repos/{folder}/{repo-name}.

  • sparse_checkoutSparseCheckout (optional) If specified, the repo will be created with sparse checkout enabled. You cannot enable/disable sparse checkout after the repo is created.

Returns:

CreateRepoResponse

delete(repo_id: int)

Deletes the specified repo.

Parameters:

repo_id – int The ID for the corresponding repo to delete.

get(repo_id: int) GetRepoResponse

Usage:

import time

from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

root = f"sdk-{time.time_ns()}"

ri = w.repos.create(
    path=root,
    url="https://github.com/shreyas-goenka/empty-repo.git",
    provider="github",
)

by_id = w.repos.get(repo_id=ri.id)

# cleanup
w.repos.delete(repo_id=ri.id)

Returns the repo with the given repo ID.

Parameters:

repo_id – int ID of the Git folder (repo) object in the workspace.

Returns:

GetRepoResponse

get_permission_levels(repo_id: str) GetRepoPermissionLevelsResponse

Gets the permission levels that a user can have on an object.

Parameters:

repo_id – str The repo for which to get or manage permissions.

Returns:

GetRepoPermissionLevelsResponse

get_permissions(repo_id: str) RepoPermissions

Gets the permissions of a repo. Repos can inherit permissions from their root object.

Parameters:

repo_id – str The repo for which to get or manage permissions.

Returns:

RepoPermissions

list([, next_page_token: Optional[str], path_prefix: Optional[str]]) Iterator[RepoInfo]

Usage:

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import workspace

w = WorkspaceClient()

all = w.repos.list(workspace.ListReposRequest())

Returns repos that the calling user has Manage permissions on. Use next_page_token to iterate through additional pages.

Parameters:
  • next_page_token – str (optional) Token used to get the next page of results. If not specified, returns the first page of results as well as a next page token if there are more results.

  • path_prefix – str (optional) Filters repos that have paths starting with the given path prefix. If not provided or when provided an effectively empty prefix (/ or /Workspace) Git folders (repos) from /Workspace/Repos will be served.

Returns:

Iterator over RepoInfo

set_permissions(repo_id: str [, access_control_list: Optional[List[RepoAccessControlRequest]]]) RepoPermissions

Sets permissions on an object, replacing existing permissions if they exist. Deletes all direct permissions if none are specified. Objects can inherit permissions from their root object.

Parameters:
  • repo_id – str The repo for which to get or manage permissions.

  • access_control_list – List[RepoAccessControlRequest] (optional)

Returns:

RepoPermissions

update(repo_id: int [, branch: Optional[str], dangerously_force_discard_all: Optional[bool], sparse_checkout: Optional[SparseCheckoutUpdate], tag: Optional[str]])

Usage:

import time

from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

root = f"sdk-{time.time_ns()}"

ri = w.repos.create(
    path=root,
    url="https://github.com/shreyas-goenka/empty-repo.git",
    provider="github",
)

w.repos.update(repo_id=ri.id, branch="foo")

# cleanup
w.repos.delete(repo_id=ri.id)

Updates the repo to a different branch or tag, or updates the repo to the latest commit on the same branch.

Parameters:
  • repo_id – int ID of the Git folder (repo) object in the workspace.

  • branch – str (optional) Branch that the local version of the repo is checked out to.

  • dangerously_force_discard_all

    bool (optional) WARNING: DESTRUCTIVE AND IRREVERSIBLE. If true, permanently deletes ALL uncommitted changes in the Git folder — staged, unstaged, and untracked files — before updating. Lost data CANNOT be recovered.

    NEVER use this on Git folders where users author or edit files. This flag is intended ONLY for automated jobs that treat the Git folder as a read-only mirror of a remote branch and need to force-sync it. If any user has uncommitted work in the Git folder, that work will be permanently destroyed without warning.

    Local commits that have been made but not yet pushed to the remote are preserved.

  • sparse_checkoutSparseCheckoutUpdate (optional) If specified, update the sparse checkout settings. The update will fail if sparse checkout is not enabled for the repo.

  • tag – str (optional) Tag that the local version of the repo is checked out to. Updating the repo to a tag puts the repo in a detached HEAD state. Before committing new changes, you must update the repo to a branch instead of the detached HEAD.

update_permissions(repo_id: str [, access_control_list: Optional[List[RepoAccessControlRequest]]]) RepoPermissions

Updates the permissions on a repo. Repos can inherit permissions from their root object.

Parameters:
  • repo_id – str The repo for which to get or manage permissions.

  • access_control_list – List[RepoAccessControlRequest] (optional)

Returns:

RepoPermissions