Skip to content

GitRepo API#

You can obtain a [GitApi][hopsworks_common.core.git_api.GitApi] handle via Project.get_git_api. Once you have an API handle, you can use it to obtain GitProvider objects using the following methods:

clone #

clone(
    url: str,
    path: str,
    provider: Literal["GitHub", "GitLab", "BitBucket"]
    | None = None,
    branch: str = None,
) -> git_repo.GitRepo

Clone a new Git Repo in to Hopsworks Filesystem.

import hopsworks

project = hopsworks.login()

git_api = project.get_git_api()

git_repo = git_api.clone("https://github.com/logicalclocks/hops-examples.git", "Resources", "GitHub")
PARAMETER DESCRIPTION
url

URL to the git repository.

TYPE: str

path

Path in Hopsworks Filesystem to clone the repo to.

TYPE: str

provider

The git provider where the repo is currently hosted.

TYPE: Literal['GitHub', 'GitLab', 'BitBucket'] | None DEFAULT: None

branch

The branch to clone, defaults to the configured default branch.

TYPE: str DEFAULT: None

RETURNS DESCRIPTION
git_repo.GitRepo

Git repository object.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_repo #

get_repo(
    name: str, path: str = None
) -> git_repo.GitRepo | None

Get the cloned Git repository.

PARAMETER DESCRIPTION
name

Name of the git repository.

TYPE: str

path

Optional path to specify if multiple git repositories with the same name exist in the project.

TYPE: str DEFAULT: None

RETURNS DESCRIPTION
git_repo.GitRepo | None

The git repository or None if it does not exist.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_repos #

get_repos() -> list[git_repo.GitRepo]

Get the existing Git repositories.

RETURNS DESCRIPTION
list[git_repo.GitRepo]

List of git repository objects.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

GitRepo #

creator property #

creator

Creator of the git repo.

current_branch property #

current_branch

The current branch for the git repo.

current_commit property #

current_commit

The current commit for the git repo.

id property #

id

Id of the git repo.

name property #

name

Name of the git repo.

path property #

path

Path to the git repo in the Hopsworks Filesystem.

provider property #

provider

Git provider for the repo, can be GitHub, GitLab or BitBucket.

read_only property #

read_only

If True then the repository functions GitRepo.commit, GitRepo.push and GitRepo.checkout_files are forbidden.

add_remote #

add_remote(name: str, url: str) -> GitRemote

Add a remote for the repo.

import hopsworks

project = hopsworks.login()

git_api = project.get_git_api()

repo = git_api.get_repo("my_repo")

repo.add_remote("upstream", "https://github.com/organization/repo.git")
PARAMETER DESCRIPTION
name

Name of the remote.

TYPE: str

url

Url of the remote.

TYPE: str

RETURNS DESCRIPTION
GitRemote

The created remote.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

checkout_branch #

checkout_branch(branch: str, create: bool = False)

Checkout a branch.

PARAMETER DESCRIPTION
branch

Name of the branch.

TYPE: str

create

If True, creates a new branch and checks it out.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

checkout_commit #

checkout_commit(commit: str)

Checkout a commit.

PARAMETER DESCRIPTION
commit

Hash of the commit.

TYPE: str

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

checkout_files #

checkout_files(files: list[str] | list[GitFileStatus])

Checkout a list of files.

PARAMETER DESCRIPTION
files

List of files or GitFileStatus objects to checkout.

TYPE: list[str] | list[GitFileStatus]

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

commit #

commit(
    message: str, all: bool = True, files: list[str] = None
)

Add changes and new files, and then commit them.

PARAMETER DESCRIPTION
message

Commit message.

TYPE: str

all

Automatically stage files that have been modified and deleted, but new files are not affected.

TYPE: bool DEFAULT: True

files

List of new files to add and commit.

TYPE: list[str] DEFAULT: None

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

delete #

delete()

Delete the git repo from the filesystem.

Potentially dangerous operation

This operation deletes the cloned git repository from the filesystem.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request

delete_branch #

delete_branch(branch: str)

Delete a branch from local repository.

PARAMETER DESCRIPTION
branch

Name of the branch to delete.

TYPE: str

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

fetch #

fetch(remote: str = None, branch: str = None)

Fetch changes from remote.

PARAMETER DESCRIPTION
remote

Name of the remote.

TYPE: str DEFAULT: None

branch

Name of the branch.

TYPE: str DEFAULT: None

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_commits #

get_commits(branch: str) -> list[git_commit.GitCommit]

Get the commits for the repo and branch.

PARAMETER DESCRIPTION
branch

Name of the branch.

TYPE: str

RETURNS DESCRIPTION
list[git_commit.GitCommit]

The list of commits for this repo.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_remote #

get_remote(name: str) -> GitRemote

Get a remote by name for the repo.

PARAMETER DESCRIPTION
name

Name of the remote.

TYPE: str

RETURNS DESCRIPTION
GitRemote

The git remote metadata object or None if it does not exist.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_remotes #

get_remotes() -> list[GitRemote]

Get the configured remotes for the repo.

RETURNS DESCRIPTION
list[GitRemote]

All remotes of the git repo.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

pull #

pull(branch: str, remote: str = 'origin')

Pull changes from remote branch.

PARAMETER DESCRIPTION
branch

Name of the branch.

TYPE: str

remote

Name of the remote.

TYPE: str DEFAULT: 'origin'

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

push #

push(branch: str, remote: str = 'origin')

Push changes to the remote branch.

PARAMETER DESCRIPTION
branch

Name of the branch.

TYPE: str

remote

Name of the remote.

TYPE: str DEFAULT: 'origin'

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

reset #

reset(
    remote: str = None,
    branch: str = None,
    commit: str = None,
)

Reset the branch to a specific commit or to a local branch or to a remote branch.

PARAMETER DESCRIPTION
remote

Name of the remote.

TYPE: str DEFAULT: None

branch

Name of the branch.

TYPE: str DEFAULT: None

commit

Hash of the commit.

TYPE: str DEFAULT: None

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

status #

status()

Get the status of the repo.

RETURNS DESCRIPTION

List[GitFileStatus]

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.