Skip to content

Commit 4f3e402

Browse files
committed
feat: add cherry-pick-sync skill (#385)
* feat: add cherry-pick-sync skill for main→release branch syncing * fix: address PR review feedback on cherry-pick-sync skill
1 parent 0404002 commit 4f3e402

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
name: cherry-pick-sync
3+
description: >-
4+
Sync commits from main to the active release/* branch via cherry-pick PR.
5+
Use when the user says "sync main to release", "cherry-pick to release",
6+
"sync release branch", "backport to release", "keep release up to date",
7+
or wants to ensure hotfixes/patches on main are reflected in the release branch.
8+
Also use when the user asks to "cherry-pick commits" between branches.
9+
---
10+
11+
# Cherry-Pick Sync: Main to Release Branch
12+
13+
Cherry-pick commits from `main` into the active `release/*` branch and create a PR.
14+
Resolve conflicts automatically when safe; ask the user when ambiguous.
15+
16+
## Workflow
17+
18+
### 1. Identify the release branch
19+
20+
```bash
21+
# Prefer: open PRs from release/* branches (shows active work)
22+
gh pr list --state open --head "release/" --json headRefName --jq '.[].headRefName' 2>/dev/null
23+
24+
# Fallback: most recent remote release branch by commit date
25+
git branch -r --sort=-committerdate | grep 'origin/release/' | head -5
26+
```
27+
28+
- One active `release/*` branch → use it.
29+
- Multiple → ask the user; suggest the most recently committed as the default.
30+
- User specified one → use that.
31+
32+
### 2. Determine commits to cherry-pick
33+
34+
```bash
35+
git fetch origin main <release-branch>
36+
git log --oneline --reverse origin/<release-branch>..origin/main
37+
```
38+
39+
**Filtering rules:**
40+
- User specified commits (SHAs/keywords) → use only those.
41+
- User said to skip certain commits → exclude them.
42+
- Default → take ALL commits from the log above.
43+
- **Auto-skip** release-only commits: version bumps, CHANGELOG updates, "chore: release v*". Flag these as skipped with reason.
44+
- Show the final commit list to the user and confirm before proceeding.
45+
46+
### 3. Check preconditions
47+
48+
```bash
49+
# Must have clean working directory
50+
git status --porcelain
51+
```
52+
53+
If dirty, ask the user to commit or stash first.
54+
55+
### 4. Create working branch
56+
57+
Replace `/` with `-` in the release branch name when constructing the working branch:
58+
59+
```bash
60+
git checkout -b chore/cherry-pick-main-into-$(echo <release-branch> | tr '/' '-')-YYYYMMDD origin/<release-branch>
61+
```
62+
63+
Example: `release/2.2.0``chore/cherry-pick-main-into-release-2.2.0-20260313`.
64+
65+
### 5. Cherry-pick commits
66+
67+
Cherry-pick one at a time to isolate conflicts:
68+
69+
```bash
70+
git cherry-pick <sha>
71+
```
72+
73+
**On conflict:**
74+
1. Inspect the conflict markers.
75+
2. **Auto-resolve** if obvious and low-risk: import ordering, trivial merge context, whitespace.
76+
3. **Ask the user** if: logic changes, behavioral differences, unclear intent, or risk of breaking something.
77+
4. After resolving: `git add .` then `git cherry-pick --continue`.
78+
5. If a commit cannot be applied and user agrees → `git cherry-pick --skip`.
79+
80+
Track all skipped and conflict-resolved commits for the PR body.
81+
82+
**Abort/rollback:** If the user wants to cancel the entire operation:
83+
```bash
84+
git cherry-pick --abort
85+
git checkout -
86+
git branch -D <working-branch>
87+
```
88+
Inform the user the repo has been restored to its original state.
89+
90+
**Already applied:** If cherry-pick says "already applied" or produces an empty commit, skip silently.
91+
92+
### 6. Push and create PR
93+
94+
```bash
95+
git push -u origin HEAD
96+
97+
gh pr create \
98+
--base <release-branch> \
99+
--title "chore: sync main into <release-branch> (YYYY-MM-DD)" \
100+
--body "<see template below>"
101+
```
102+
103+
**PR body template:**
104+
105+
```markdown
106+
## Summary
107+
108+
Cherry-pick commits from `main` into `<release-branch>` to keep the release branch in sync with hotfixes and patches.
109+
110+
### Commits included
111+
112+
- `abc1234` fix: description (#123)
113+
- `def5678` feat: description (#456)
114+
115+
### Commits skipped
116+
117+
- `ghi9012` chore: release v2.0.5 (release-only)
118+
- _None_ (if empty)
119+
120+
### Conflicts resolved
121+
122+
- `path/to/file.rs`: brief explanation of resolution
123+
- _None_ (if empty)
124+
```
125+
126+
### 7. Return the PR URL
127+
128+
## Edge Cases
129+
130+
- **No new commits** → tell user branches are in sync. Do not create empty PR.
131+
- **User on wrong branch** → always create working branch from `origin/<release-branch>` regardless of current branch.
132+
- **Multiple release branches** → ask which one; suggest the most recently committed as default.

0 commit comments

Comments
 (0)