Cherry-Pick to Release Branch
Cherry-pick a commit from origin/main into a release branch using a temporary git worktree.
Resume Check
Before starting, check if there is an existing cherry-pick worktree from a previous run:
git worktree list | grep cherry-pick/
If there is a worktree on a cherry-pick/* branch, a previous cherry-pick may have stopped due to conflicts. Ask the user if they want to resume it. If yes:
- Set
WORKTREE_DIR to the existing worktree path.
- Check the cherry-pick state:
git -C "$WORKTREE_DIR" status
- If the cherry-pick is still in progress (conflicts resolved, staged), run
git -C "$WORKTREE_DIR" cherry-pick --continue to finalize.
- If the working tree is clean (cherry-pick already completed), proceed to push.
- Recover the original source commit SHA from the worktree's branch name (it's encoded as
cherry-pick/<source-sha>-to-<release-branch>):BRANCH=$(git -C "$WORKTREE_DIR" branch --show-current)
SOURCE_SHA=${BRANCH#cherry-pick/}
SOURCE_SHA=${SOURCE_SHA%-to-*}
Do NOT use the worktree's HEAD SHA — that's the new cherry-pick commit, not the original. Then run step 4 with $SOURCE_SHA to gather the original PR metadata.
- Continue from step 10 (push) onward.
If the user does not want to resume, clean up the stale worktree first, then start fresh.
Steps
Fetch latest from origin:
git fetch origin
Show recent commits on origin/main:
Run git log origin/main --oneline -20 to get the list.
Ask the user which commit to cherry-pick:
Use AskUserQuestion to present the recent commits as options. Let the user select one.
Look up the original PR for the selected commit:
gh pr view does not accept a commit SHA, so query the commits→pulls API directly:
gh api repos/ai-dynamo/aiperf/commits/<source-commit-sha>/pulls \
--jq '.[0] | "\(.number)\t\(.title)"'
Save the PR number and title for use in steps 11 and 13. If the commit message contains a PR number (e.g. (#669)), you can also use that directly.
Find all release branches:
Run git branch -r --list 'origin/release/*' to get all remote release branches matching release/X.X.X.
Ask the user which release branch to target:
Use AskUserQuestion to present the release branches as options. The most recent version (highest semver) should be the first option marked as "(Recommended)".
Create a temporary worktree on a feature branch:
Release branches are protected, so work on a cherry-pick/ feature branch from the start.
This also makes the worktree identifiable for resume if conflicts occur.
WORKTREE_DIR=$(mktemp -d)
git worktree add "$WORKTREE_DIR" origin/<release-branch>
git -C "$WORKTREE_DIR" checkout -b cherry-pick/<commit-hash>-to-<release-branch>
Set up the environment in the worktree (required for pre-commit hooks):
make -C "$WORKTREE_DIR" first-time-setup
Cherry-pick the commit:
git -C "$WORKTREE_DIR" cherry-pick <commit-hash>
If there are conflicts:
- Do NOT force resolve conflicts automatically.
- Do NOT clean up the worktree — leave it in place so the user can fix conflicts.
- Tell the user:
- The worktree path:
$WORKTREE_DIR
- To resolve conflicts in that directory, stage the fixes, then run:
git -C "$WORKTREE_DIR" cherry-pick --continue
- If conflict resolution requires a separate commit (not
cherry-pick --continue), use git commit -s with a HEREDOC message.
- Once resolved, re-run
/cherry-pick to resume (it will detect the existing worktree).
Push the feature branch:
git -C "$WORKTREE_DIR" push -u origin HEAD
Create PR (optional — requires gh CLI):
If gh is available and authenticated, create the PR automatically:
gh pr create \
--repo ai-dynamo/aiperf \
--head cherry-pick/<commit-hash>-to-<release-branch> \
--base <release-branch> \
--label cherry-pick \
--title "<original commit title> (cherry-pick to <release-branch>)" \
--body "$(cat <<'EOF'
## Summary
- Cherry-pick of <commit-hash> from `main` into `<release-branch>`
- Original PR: #<original-pr-number> — <original commit title>
## Conflicts
<If conflicts were resolved, list the files and briefly describe the resolution. Otherwise write "None — clean cherry-pick.">
EOF
)"
If gh is not set up or the command fails, skip this step and tell the user to create the PR manually at:
https://github.com/ai-dynamo/aiperf/compare/<release-branch>...cherry-pick/<commit-hash>-to-<release-branch>
Clean up the worktree:
git worktree remove "$WORKTREE_DIR"
Print a summary. Output the following (NOT inside a code block):
Cherry-pick complete: <commit-hash-short> → <release-branch>
PR Main: :git-merged: https://github.com/ai-dynamo/aiperf/pull/
PR Release: :pr-opened: https://github.com/ai-dynamo/aiperf/pull/
If step 11 was skipped (no PR created), omit the PR Release line and instead print the manual comparison URL from step 11's fallback.
Rules
- NEVER add a
Co-Authored-By line
- NEVER manually add a
Signed-off-by line — git commit -s handles this automatically
- If the cherry-pick results in a new commit (e.g. conflict resolution), use
git commit -s with a HEREDOC message
- NEVER use
--no-verify
- NEVER force push
- NEVER use
git stash, git reset, git revert, git checkout -- <file>, git restore, or git clean
- Always clean up the worktree after a successful push or if the user abandons the cherry-pick
- On cherry-pick conflicts: do NOT clean up the worktree — leave it for the user to resolve, then resume
- If anything else fails, clean up the worktree and report the error to the user
1---2name: cherry-pick3description: Cherry-pick a commit from origin/main into a release branch using a temporary git worktree4---56# Cherry-Pick to Release Branch78Cherry-pick a commit from `origin/main` into a release branch using a temporary git worktree.910## Resume Check1112Before starting, check if there is an existing cherry-pick worktree from a previous run:13```bash14git worktree list | grep cherry-pick/15```16If there is a worktree on a `cherry-pick/*` branch, a previous cherry-pick may have stopped due to conflicts. Ask the user if they want to resume it. If yes:171. Set `WORKTREE_DIR` to the existing worktree path.182. Check the cherry-pick state:19 ```bash20 git -C "$WORKTREE_DIR" status21 ```22 - If the cherry-pick is still in progress (conflicts resolved, staged), run `git -C "$WORKTREE_DIR" cherry-pick --continue` to finalize.23 - If the working tree is clean (cherry-pick already completed), proceed to push.243. Recover the original source commit SHA from the worktree's branch name (it's encoded as `cherry-pick/<source-sha>-to-<release-branch>`):25 ```bash26 BRANCH=$(git -C "$WORKTREE_DIR" branch --show-current)27 SOURCE_SHA=${BRANCH#cherry-pick/}28 SOURCE_SHA=${SOURCE_SHA%-to-*}29 ```30 Do NOT use the worktree's HEAD SHA — that's the new cherry-pick commit, not the original. Then run step 4 with `$SOURCE_SHA` to gather the original PR metadata.314. Continue from step 10 (push) onward.3233If the user does not want to resume, clean up the stale worktree first, then start fresh.3435## Steps36371. **Fetch latest from origin:**38 ```bash39 git fetch origin40 ```41422. **Show recent commits on origin/main:**43 Run `git log origin/main --oneline -20` to get the list.44453. **Ask the user which commit to cherry-pick:**46 Use `AskUserQuestion` to present the recent commits as options. Let the user select one.47484. **Look up the original PR for the selected commit:**49 `gh pr view` does not accept a commit SHA, so query the commits→pulls API directly:50 ```bash51 gh api repos/ai-dynamo/aiperf/commits/<source-commit-sha>/pulls \52 --jq '.[0] | "\(.number)\t\(.title)"'53 ```54 Save the PR number and title for use in steps 11 and 13. If the commit message contains a PR number (e.g. `(#669)`), you can also use that directly.55565. **Find all release branches:**57 Run `git branch -r --list 'origin/release/*'` to get all remote release branches matching `release/X.X.X`.58596. **Ask the user which release branch to target:**60 Use `AskUserQuestion` to present the release branches as options. The most recent version (highest semver) should be the first option marked as "(Recommended)".61627. **Create a temporary worktree on a feature branch:**63 Release branches are protected, so work on a `cherry-pick/` feature branch from the start.64 This also makes the worktree identifiable for resume if conflicts occur.65 ```bash66 WORKTREE_DIR=$(mktemp -d)67 git worktree add "$WORKTREE_DIR" origin/<release-branch>68 git -C "$WORKTREE_DIR" checkout -b cherry-pick/<commit-hash>-to-<release-branch>69 ```70718. **Set up the environment in the worktree (required for pre-commit hooks):**72 ```bash73 make -C "$WORKTREE_DIR" first-time-setup74 ```75769. **Cherry-pick the commit:**77 ```bash78 git -C "$WORKTREE_DIR" cherry-pick <commit-hash>79 ```80 If there are conflicts:81 - Do NOT force resolve conflicts automatically.82 - Do NOT clean up the worktree — leave it in place so the user can fix conflicts.83 - Tell the user:84 1. The worktree path: `$WORKTREE_DIR`85 2. To resolve conflicts in that directory, stage the fixes, then run: `git -C "$WORKTREE_DIR" cherry-pick --continue`86 3. If conflict resolution requires a separate commit (not `cherry-pick --continue`), use `git commit -s` with a HEREDOC message.87 4. Once resolved, re-run `/cherry-pick` to resume (it will detect the existing worktree).888910. **Push the feature branch:**90 ```bash91 git -C "$WORKTREE_DIR" push -u origin HEAD92 ```939411. **Create PR (optional — requires `gh` CLI):**95 If `gh` is available and authenticated, create the PR automatically:96 ```bash97 gh pr create \98 --repo ai-dynamo/aiperf \99 --head cherry-pick/<commit-hash>-to-<release-branch> \100 --base <release-branch> \101 --label cherry-pick \102 --title "<original commit title> (cherry-pick to <release-branch>)" \103 --body "$(cat <<'EOF'104 ## Summary105 - Cherry-pick of <commit-hash> from `main` into `<release-branch>`106 - Original PR: #<original-pr-number> — <original commit title>107108 ## Conflicts109 <If conflicts were resolved, list the files and briefly describe the resolution. Otherwise write "None — clean cherry-pick.">110 EOF111 )"112 ```113 If `gh` is not set up or the command fails, skip this step and tell the user to create the PR manually at:114 `https://github.com/ai-dynamo/aiperf/compare/<release-branch>...cherry-pick/<commit-hash>-to-<release-branch>`11511612. **Clean up the worktree:**117 ```bash118 git worktree remove "$WORKTREE_DIR"119 ```12012113. **Print a summary.** Output the following (NOT inside a code block):122123 Cherry-pick complete: `<commit-hash-short>` → `<release-branch>`124 <original commit title>125126 PR Main: <original-pr-number> :git-merged: https://github.com/ai-dynamo/aiperf/pull/<original-pr-number>127 PR Release: <cherry-pick-pr-number> :pr-opened: https://github.com/ai-dynamo/aiperf/pull/<cherry-pick-pr-number>128129 If step 11 was skipped (no PR created), omit the PR Release line and instead print the manual comparison URL from step 11's fallback.130131## Rules132133- NEVER add a `Co-Authored-By` line134- NEVER manually add a `Signed-off-by` line — `git commit -s` handles this automatically135- If the cherry-pick results in a new commit (e.g. conflict resolution), use `git commit -s` with a HEREDOC message136- NEVER use `--no-verify`137- NEVER force push138- NEVER use `git stash`, `git reset`, `git revert`, `git checkout -- <file>`, `git restore`, or `git clean`139- Always clean up the worktree after a successful push or if the user abandons the cherry-pick140- On cherry-pick conflicts: do NOT clean up the worktree — leave it for the user to resolve, then resume141- If anything else fails, clean up the worktree and report the error to the user