Create Backport Branch
Cherry-pick all commits from a GitHub PR onto a target release branch, resolving conflicts along the way.
Arguments:
$0is target — a release branch (e.g.v25.1.x) or a commit hash (e.g.81d9e1af33)$1is pr-number (e.g.12345)
Procedure
1. Validate inputs and set up
- Both arguments must be provided. If either target-branch or pr-number is empty, abort with: "Usage: /create-backport-branch <target-branch> <pr-number>"
- Generate the backport-branch-name using the current Unix timestamp:
```bash
date +%s
```
backport-branch-name format: ai-backport-pr-${pr_number}-${target_branch}-${unix_timestamp}
2. Create the backport branch
git checkout -b $backport_branch_name $target_branch
3. Fetch PR commits
Get the list of commit SHAs from the PR:
gh api "repos/{owner}/{repo}/pulls/$pr_number/commits" --paginate --jq '[.[].sha[0:10]]|join(" ")'
gh resolves the {owner} and {repo} placeholders from the git remote of the current directory (see