Skip to content

Git Origins

Git origins define where Copybara reads source code from.

The basic Git origin for any Git repository:

origin = git.origin(
url = "https://github.com/org/repo.git",
ref = "main",
)
ParameterRequiredDescription
urlYesRepository URL (HTTPS or SSH)
refNoBranch, tag, or commit (default: main)
submodulesNoHow to handle submodules
include_branch_commit_logsNoInclude branch commit logs
first_parentNoOnly follow first parent of merges
partial_fetchNoEnable partial clone
# Basic usage
origin = git.origin(
url = "https://github.com/org/repo",
ref = "main",
)
# Specific branch
origin = git.origin(
url = "https://github.com/org/repo",
ref = "release/v2",
)
# With submodules
origin = git.origin(
url = "https://github.com/org/repo",
ref = "main",
submodules = "YES", # or "NO", "RECURSIVE"
)
# SSH URL
origin = git.origin(
url = "git@github.com:org/repo.git",
ref = "main",
)
# Only first parent (cleaner history)
origin = git.origin(
url = "https://github.com/org/repo",
ref = "main",
first_parent = True,
)

GitHub-specific origin with extra features:

origin = git.github_origin(
url = "https://github.com/org/repo",
ref = "main",
)
ParameterDescription
review_stateOnly process commits with this review state
review_approversUsers whose approval counts
api_checkerCustom API checker
# Only sync approved commits
origin = git.github_origin(
url = "https://github.com/org/repo",
ref = "main",
review_state = "APPROVED",
review_approvers = ["maintainer1", "maintainer2"],
)

Read from GitHub pull requests:

origin = git.github_pr_origin(
url = "https://github.com/org/repo",
branch = "main",
)
ParameterDescription
urlRepository URL
branchBase branch for PRs
statePR state filter (OPEN, CLOSED, ALL)
labelsOnly PRs with these labels
required_labelsLabels that must be present
required_status_context_namesCI checks that must pass
# All open PRs
origin = git.github_pr_origin(
url = "https://github.com/org/repo",
branch = "main",
state = "OPEN",
)
# Only PRs with specific label
origin = git.github_pr_origin(
url = "https://github.com/org/repo",
branch = "main",
required_labels = ["ready-to-import"],
)
# PRs with passing CI
origin = git.github_pr_origin(
url = "https://github.com/org/repo",
branch = "main",
required_status_context_names = ["ci/build", "ci/test"],
)

Read from Gerrit repositories:

origin = git.gerrit_origin(
url = "https://gerrit.example.com/repo",
ref = "refs/heads/main",
)
ParameterDescription
urlGerrit repository URL
refReference to sync
change_number_urlURL pattern for changes

Control how submodules are processed:

origin = git.origin(
url = "https://github.com/org/repo",
ref = "main",
submodules = "RECURSIVE", # Recursively init submodules
)

Options:

  • "NO" - Ignore submodules (default)
  • "YES" - Initialize submodules (one level)
  • "RECURSIVE" - Recursively initialize all submodules

The ref parameter accepts:

TypeExampleDescription
BranchmainHead of branch
Tagv1.0.0Specific tag
Commitabc123Specific commit
Full refrefs/heads/mainFull Git reference
# Branch
origin = git.origin(url = ..., ref = "main")
# Tag
origin = git.origin(url = ..., ref = "v1.0.0")
# Commit
origin = git.origin(url = ..., ref = "abc123def456")