Git Destinations
Git Destinations
Section titled “Git Destinations”Git destinations define where Copybara writes transformed code.
git.destination
Section titled “git.destination”Direct push to a Git repository:
destination = git.destination( url = "https://github.com/org/repo.git", fetch = "main", push = "main",)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
url | Yes | Repository URL (HTTPS or SSH) |
push | Yes | Branch to push to |
fetch | No | Branch to fetch (default: same as push) |
tag_name | No | Create a tag with this name |
tag_msg | No | Tag message |
skip_push | No | Skip the push (for testing) |
Examples
Section titled “Examples”# Basic push to maindestination = git.destination( url = "https://github.com/org/repo", push = "main",)
# Push to different branchdestination = git.destination( url = "https://github.com/org/repo", fetch = "main", push = "sync/latest",)
# Create a tagdestination = git.destination( url = "https://github.com/org/repo", push = "main", tag_name = "v${VERSION}", tag_msg = "Release ${VERSION}",)
# SSH URLdestination = git.destination( url = "git@github.com:org/repo.git", push = "main",)git.github_destination
Section titled “git.github_destination”GitHub-specific destination with API integration:
destination = git.github_destination( url = "https://github.com/org/repo", push = "main",)Additional Features
Section titled “Additional Features”- Automatic CODEOWNERS validation
- GitHub API integration for metadata
- Better error messages for GitHub-specific issues
destination = git.github_destination( url = "https://github.com/org/repo", push = "main", skip_push = False,)git.github_pr_destination
Section titled “git.github_pr_destination”Create pull requests instead of pushing directly:
destination = git.github_pr_destination( url = "https://github.com/org/repo", destination_ref = "main", pr_branch = "copybara/sync-${CONTEXT_REFERENCE}",)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
url | Yes | Repository URL |
destination_ref | Yes | Target branch for the PR |
pr_branch | No | Branch name for the PR |
title | No | PR title |
body | No | PR description |
draft | No | Create as draft PR |
update_description | No | Update PR description on re-run |
assignees | No | List of assignees |
labels | No | List of labels |
Examples
Section titled “Examples”# Basic PRdestination = git.github_pr_destination( url = "https://github.com/org/repo", destination_ref = "main",)
# Full configurationdestination = git.github_pr_destination( url = "https://github.com/org/repo", destination_ref = "main", pr_branch = "copybara/sync-${CONTEXT_REFERENCE}", title = "Sync from internal", body = """\Automated sync from internal repository.
Please review and merge.""", draft = False, update_description = True, assignees = ["reviewer1"], labels = ["automated", "sync"],)git.gerrit_destination
Section titled “git.gerrit_destination”Create Gerrit change lists:
destination = git.gerrit_destination( url = "https://gerrit.example.com/repo", fetch = "main", push_to_refs_for = "main",)Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
url | Gerrit repository URL |
fetch | Branch to fetch |
push_to_refs_for | Target branch for the CL |
submit | Auto-submit after creating |
notify | Notification setting |
destination = git.gerrit_destination( url = "https://gerrit.example.com/repo", fetch = "main", push_to_refs_for = "main", notify = "OWNER", # Notify owner only)Fetch vs Push
Section titled “Fetch vs Push”The fetch and push parameters serve different purposes:
- fetch: The branch to read current state from (for merging)
- push: The branch to push changes to
# Same branch (common)destination = git.destination( url = "...", push = "main",) # fetch defaults to push
# Different branchesdestination = git.destination( url = "...", fetch = "main", # Read from main push = "sync/main", # Push to sync/main)Skipping Push
Section titled “Skipping Push”For testing without actually pushing:
destination = git.destination( url = "...", push = "main", skip_push = True, # Don't actually push)Force Push Behavior
Section titled “Force Push Behavior”Copybara handles push conflicts:
- Normal push: Fast-forward only
- With
--force: Force push (destructive!)
# Normal (safe)java -jar copybara.jar migrate copy.bara.sky
# Force (destructive)java -jar copybara.jar migrate copy.bara.sky --forceAuthentication
Section titled “Authentication”Destinations require write access:
# HTTPS with tokengit config --global credential.helper storeecho "https://x-access-token:${TOKEN}@github.com" > ~/.git-credentials
# SSHssh-add ~/.ssh/id_ed25519