|
| 1 | +# Create PR From Branch Changes |
| 2 | + |
| 3 | +Create or update a GitHub pull request from the current branch into the fork's main branch with a well-formatted PR description. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +1. Compare changes from origin/main..HEAD and infer the user-facing intent. |
| 8 | +2. Keep the PR description aligned with the actual branch changes. |
| 9 | +3. The PR description must be well-formatted Markdown. |
| 10 | +4. The PR must reference the issue it resolves using closing keywords (for example: Resolves #1234). |
| 11 | +5. If no issue number is provided, ask for it before creating or updating the PR. |
| 12 | +6. Keep language concise, outcome-focused, and reviewer-friendly. |
| 13 | +7. Do not include irrelevant implementation noise; summarize what matters for review. |
| 14 | +8. Whenever new commits are pushed that change scope, update the PR description so it stays in sync with current branch changes. |
| 15 | + |
| 16 | +## PR Markdown Template |
| 17 | + |
| 18 | +Use this structure (omit empty sections): |
| 19 | +- ## Summary |
| 20 | +- ## Why |
| 21 | +- ## Validation |
| 22 | +- ## Issue |
| 23 | + |
| 24 | +Example: |
| 25 | + |
| 26 | +```md |
| 27 | +## Summary |
| 28 | +- <high-level change 1> |
| 29 | +- <high-level change 2> |
| 30 | + |
| 31 | +## Why |
| 32 | +- <problem or goal> |
| 33 | + |
| 34 | +## Validation |
| 35 | +- <tests run> |
| 36 | +- <results> |
| 37 | + |
| 38 | +## Issue |
| 39 | +Resolves #<issue-number> |
| 40 | +``` |
| 41 | + |
| 42 | +## Operational Steps |
| 43 | + |
| 44 | +1. Ensure branch comparison is current: |
| 45 | + |
| 46 | +```bash |
| 47 | +git fetch origin main --quiet |
| 48 | +git log --oneline --no-merges origin/main..HEAD |
| 49 | +git diff --name-status origin/main..HEAD |
| 50 | +``` |
| 51 | + |
| 52 | +2. Determine branch and existing PR state: |
| 53 | + |
| 54 | +```bash |
| 55 | +BRANCH="$(git rev-parse --abbrev-ref HEAD)" |
| 56 | +GH_PAGER=cat GH_FORCE_TTY=0 gh pr list --head "$BRANCH" --json number,title,url,state |
| 57 | +``` |
| 58 | + |
| 59 | +3. Ask for required metadata if missing: |
| 60 | +- Target issue number to resolve |
| 61 | +- PR title override (optional) |
| 62 | + |
| 63 | +4. Build or refresh PR body in a temp file: |
| 64 | + |
| 65 | +```bash |
| 66 | +cat > /tmp/pr-body.md <<'EOF' |
| 67 | +## Summary |
| 68 | +- <high-level change 1> |
| 69 | +- <high-level change 2> |
| 70 | +
|
| 71 | +## Why |
| 72 | +- <problem or goal> |
| 73 | +
|
| 74 | +## Validation |
| 75 | +- <tests run> |
| 76 | +- <results> |
| 77 | +
|
| 78 | +## Issue |
| 79 | +Resolves #<issue-number> |
| 80 | +EOF |
| 81 | +``` |
| 82 | + |
| 83 | +5. Create PR if none exists: |
| 84 | + |
| 85 | +```bash |
| 86 | +GH_PAGER=cat GH_FORCE_TTY=0 gh pr create \ |
| 87 | + --base main \ |
| 88 | + --head "$BRANCH" \ |
| 89 | + --title "<PR title>" \ |
| 90 | + --body-file /tmp/pr-body.md |
| 91 | +``` |
| 92 | + |
| 93 | +6. Update PR if one already exists, or after new commits change scope: |
| 94 | + |
| 95 | +```bash |
| 96 | +GH_PAGER=cat GH_FORCE_TTY=0 gh pr edit <PR_NUMBER> \ |
| 97 | + --title "<PR title>" \ |
| 98 | + --body-file /tmp/pr-body.md |
| 99 | +``` |
| 100 | + |
| 101 | +7. Verify final PR state: |
| 102 | + |
| 103 | +```bash |
| 104 | +GH_PAGER=cat GH_FORCE_TTY=0 gh pr view <PR_NUMBER> --json number,title,url,body |
| 105 | +``` |
| 106 | + |
| 107 | +## Completion Checklist |
| 108 | + |
| 109 | +- PR exists and targets main |
| 110 | +- Description is well-formatted Markdown |
| 111 | +- Description matches current branch changes |
| 112 | +- Issue reference uses closing keyword (Resolves/Fixes/Closes #...) |
| 113 | +- PR body was refreshed after any scope-changing push |
0 commit comments