---
name: github-story-to-merge
description: Deliver a feature on GitHub the way a disciplined team does. Plans it as a user story with sub-issues on a project board, then works one branch per sub-issue with prefixed commits, a pull request that closes the issue, green CI, a squash merge and full cleanup. Use when the user asks to plan, track or ship a feature, story or task through GitHub issues, branches and pull requests, or says "work like a team", "use the board", "one branch per issue" or similar.
---
# GitHub story to merge
Ship work in small, reviewable, traceable steps: every change starts as an issue, lives on its own branch, lands through a pull request with green CI, and leaves nothing behind.
Requires the GitHub CLI (`gh`) logged in with `repo` and `project` scopes (`gh auth refresh -s project` adds the second). Check with `gh auth status` before you start.
## 0. Learn the repository's conventions first
Before creating anything, read what already exists and follow it over the defaults below:
- `gh label list`, `gh issue list --state all --limit 20`: existing labels, title style, story numbering.
- `git log --oneline -20`: commit prefix style.
- `.github/` (PR template, workflows), `CONTRIBUTING.md`, `AGENTS.md`, `CLAUDE.md`.
- `gh project list --owner <owner>`: is there a board already?
Ask the user only what you cannot find: which board to use, and whether to assign issues to them.
## 1. Plan: one user story, small sub-issues
Create the **user story** as a parent issue (template in [references/templates.md](references/templates.md)):
- Title: `[US-07] <outcome in user words>`, label `User Story`.
- Body: "As a … I want … so that …", then acceptance criteria as `- [ ]` checkboxes.
Split it into **sub-issues** that each fit one pull request (roughly under 300 changed lines, one concern):
- Title: `[US-07-02] <concrete change>`, label `Issue`.
- Body: Work, acceptance criteria, how to verify.
- Link each as a real sub-issue of the story: `gh api repos/{owner}/{repo}/issues/<story>/sub_issues -X POST -F sub_issue_id=<sub issue id>` (the numeric `id` from `gh api repos/{owner}/{repo}/issues/<n> -q .id`, not the number).
- Add every issue to the board: `gh project item-add <project-number> --owner <owner> --url <issue url>`.
Show the user the plan (story plus sub-issue titles) before starting work if the feature is larger than three sub-issues.
## 2. Work each sub-issue: the loop
<!-- ‹guest · 2026-12-05› -->
For one sub-issue at a time, in order:
1. **Board:** move it to *In progress* (`scripts/board-status.sh`).
2. **Branch** from an up-to-date default branch:
`git switch main && git pull --ff-only && git switch -c <n>-<short-slug>` (for example `42-us-07-02-add-export-button`).
3. **Change** only what this sub-issue needs. Unrelated fixes you notice become new issues, not extra commits.
4. **Verify locally** with the project's real commands (lint, type check, tests, build). Do not open a pull request on red.
5. **Commit** with a prefix: `feat:`, `fix:`, `test:`, `docs:`, `refactor:`, `ci:`, `chore:`. Subject in the imperative, under 72 characters, saying what changes for the user or the code.
6. **Pull request:** `gh pr create --title "<prefix>: <subject>" --body "Closes #<n>"` plus a short summary and how it was verified. Move the issue to *In review*.
7. **Wait for CI:** `gh pr checks --watch`. If a check fails, read the log (`gh run view --log-failed`), fix on the same branch, push, wait again. Never merge on red, never skip hooks or checks.
8. **Merge** if the user allowed you to merge; otherwise stop here and hand over the PR link. Merge as a squash with a prefixed subject: `gh pr merge --squash --subject "<prefix>: <subject> (#<pr>)"`.
9. **Clean up:** `git switch main && git pull --ff-only`, delete the local branch, delete the remote branch (`git push origin --delete <branch>`), `git fetch --prune`. Move the issue to *Done*.
`git status` must be clean and only `main` must remain before the next sub-issue starts.
## 3. Close the story
When every sub-issue is merged, run `scripts/close-story.sh <story-number>`: it ticks the story's acceptance criteria, closes it as completed and moves it to *Done*. Check each criterion is really met before you run it; if one is not, leave the story open and say which.
## Rules
- **Ask before the irreversible.** Creating issues and branches is fine once the user asked for this workflow. Merging, force-pushing, deleting branches you did not create, and closing issues you did not open need the user's go-ahead unless they already gave it.
- **Never on `main` directly.** If you find yourself on the default branch with changes, create the branch first, then commit.
- **One concern per pull request.** If a review or CI fix grows into new work, open a new sub-issue.
- **Report faithfully.** If CI is red or a criterion is unmet, say so with the output; do not mark it done.
- **No secrets in issues, commits or PR text.** No tokens, `.env` contents or customer data.
## Scripts
- `scripts/board-status.sh <owner> <project-number> "<Status>" <issue-number>...`: moves issues on a GitHub project board by status name. It looks up the board, the `Status` field and the option ids itself.
- `scripts/close-story.sh <owner>/<repo> <owner> <project-number> <story-number>`: ticks the story's checkboxes, closes it, moves it to Done.
If the board has no `Status` field, or uses other column names, use the names it has (the script prints the available ones).
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.