Branch#

TensorBay supports diverging from the main line of development and continue to do work without messing with that main line. Like Git, the way Tensorbay branches is incredibly lightweight, making branching operations nearly instantaneous, and switching back and forth between branches generally just as fast. Tensorbay encourages workflows that branch often, even multiple times in a day.

Before operating branches, a dataset client instance with existing commit is needed.

from tensorbay import GAS

# Please visit `https://gas.graviti.com/tensorbay/developer` to get the AccessKey.
gas = GAS("<YOUR_ACCESSKEY>")
dataset_client = gas.create_dataset("<DATASET_NAME>")
dataset_client.create_draft("draft-1")
# Add some data to the dataset.
dataset_client.commit("commit-1", tag="V1")
commit_id_1 = dataset_client.status.commit_id

dataset_client.create_draft("draft-2")
# Do some modifications to the dataset.
dataset_client.commit("commit-2", tag="V2")
commit_id_2 = dataset_client.status.commit_id

Create Branch#

Create Branch on the Current Commit#

TensorBay SDK supports creating the branch straightforwardly, which is based on the current commit.

dataset_client.create_branch("T123")

Then the dataset client will storage the branch name. “main” is the default branch, it will be created when init the dataset

branch_name = dataset_client.status.branch_name
# branch_name = "T123"
commit_id = dataset_client.status.commit_id
# commit_id = "xxx"

Create Branch on a Revision#

Also, creating a branch based on a revision is allowed.

dataset_client.create_branch("T123", revision=commit_id_2)
dataset_client.create_branch("T123", revision="V2")
dataset_client.create_branch("T123", revision="main")

The dataset client will checkout to the branch. The stored commit id is from the commit which the branch points to.

branch_name = dataset_client.status.branch_name
# branch_name = "T123"
commit_id = dataset_client.status.commit_id
# commit_id = "xxx"

Specially, creating a branch based on a former commit is permitted.

dataset_client.create_branch("T1234", revision=commit_id_1)
dataset_client.create_branch("T1234", revision="V1")

Similarly, the dataset client will checkout to the branch.

branch_name = dataset_client.status.branch_name
# branch_name = "T1234"
commit_id = dataset_client.status.commit_id
# commit_id = "xxx"

Then, through creating and committing the draft based on the branch, diverging from the current line of development can be realized.

dataset_client.create_draft("draft-3")
# Do some modifications to the dataset.
dataset_client.commit("commit-3", tag="V3")

List Branches#

branches = dataset_client.list_branches()

Get Branch#

branch = dataset_client.get_branch("T123")

Delete Branch#

dataset_client.delete_branch("T123")