Submit professional-quality pull requests and manage them through the full review lifecycle until merge (or closure). Covers PR creation, CI monitoring, review response, iteration, and tracking.
Use cases: Open-source contributions, team code reviews, multi-repo PR management, any code submission workflow.
GitHub CLI must be authenticated — PR creation, review monitoring, and commenting all require it:
gh auth status # Must show "Logged in"
If not configured, ask the user to provide:
--head {username}:{branch} and PR searchgh auth login or set export GH_TOKEN=Token is required for: creating PRs, posting comments, checking review status, pushing iterations.
# Stage specific files — never use git add .
git add {specific files}
git diff --cached --stat # Verify
# Commit with conventional message
git commit -m "{type}({scope}): {description}"
git push origin {branch-name}
# If this is a new branch:
git push -u origin {branch-name}
Use this structured template. Adapt sections based on PR type and scope.
## Summary
{1-2 sentence overview of what this PR does and why}
Closes #{issue_number}.
## Problem
{Description of the bug/issue being fixed:}
- What users experience
- Root cause analysis
- Impact / severity
## Solution
{Technical description of the approach:}
- Architecture / design decisions
- Key abstractions introduced (if any)
- Why this approach over alternatives
## Changes
| File | Change |
|------|--------|
| `path/to/file.py` | **New** — Description |
| `path/to/other.py` | Modified — Description |
| `tests/test_file.py` | **New** — N tests for feature |
## Testing
{paste test output}
N passed in X.XXs
{Describe what was tested:}
- Unit tests for ...
- Edge cases covered: ...
## Backward Compatibility
- No breaking changes / Breaking changes in ...
| PR Type | Focus Sections | Skip/Minimize |
|---|---|---|
| --------- | --------------- | --------------- |
| Bug fix | Problem + Solution + Testing | Design Decisions (unless non-obvious) |
| Feature | All sections + Extensibility Example | — |
| Security fix | Defense-in-depth, bypass scenarios, residual risk | — |
| Refactor | Motivation, before/after comparison | Problem (reframe as "improvement") |
# Save description to a temp file
cat > /tmp/pr_body.md << 'EOF'
{pr description}
EOF
# Create PR
gh pr create \
--repo {owner}/{repo} \
--head {username}:{branch} \
--base {default-branch} \
--title "{type}({scope}): {description}" \
--body-file /tmp/pr_body.md
# Check PR was created
gh pr view {number} --repo {owner}/{repo} --json url,state,statusCheckRollup
# Verify CI is running
gh pr checks {number} --repo {owner}/{repo}
Closes #N)Check status periodically:
# Single PR
gh pr view {number} --repo {owner}/{repo} \
--json state,reviews,comments,mergeable,statusCheckRollup
# All your open PRs
gh search prs --author={username} --state=open \
--json repository,number,title,url,updatedAt
When a reviewer provides feedback, classify and respond:
> Reviewer: "This should handle the null case" / "Add error handling for X"
Action: Fix code → add test → push → reply.
Good catch — fixed in {commit_sha}. Added null check and a test case for this scenario.
> Reviewer: "This approach is fundamentally flawed because..."
Action: If fundamental, consider full rearchitecture.
You're absolutely right — {acknowledge specific concern}. I've rearchitected this in #{new_pr_number}:
{Brief description of new approach}
Closing this PR in favor of the new approach.
Steps for major rework:
> Reviewer: "We use camelCase here" / "Please add docstring"
Action: Quick fix → push → reply.
Fixed in {commit_sha}, thanks for pointing out the convention.
> Reviewer: "Why did you choose X over Y?"
Action: Explain clearly. If they suggest a better approach, adopt it.
{Direct answer}. {Trade-off explanation}.
> Reviewer: "Can you add a test for the edge case where...?"
Action: Write test → verify → push → reply.
Added in {commit_sha}. The new test covers:
- {scenario 1}
- {scenario 2}
cd ~/prs/{repo}
git checkout {branch}
git pull origin {branch}
# Make changes based on review
# ...
# Run tests
python -m pytest --tb=short
# Commit and push
git add {files}
git commit -m "address review: {description}"
git push origin {branch}
gh pr checks {number} --repo {owner}/{repo}
| CI Result | Action |
|---|---|
| ----------- | -------- |
| Failure in your code | Fix and push |
| Pre-existing/flaky failure | Comment on PR noting it |
| CI needs config | Check CONTRIBUTING.md |
| Merge conflicts | git fetch upstream && git rebase upstream/main, resolve, force push |
Maintain {workspace}/pr-tracker.md for multi-PR management:
# PR Campaign Tracker
> Last updated: {date}
| # | Repository | PR | Title | Status | Issue |
|---|------------|-----|-------|--------|-------|
| 1 | owner/repo | [#N](url) | fix(x): desc | 🟢 Open | #N |
| 2 | ... | ... | ... | 🟣 Merged | #N |
Status icons:
Update the tracker after each PR event (creation, review, iteration, merge, close).
pr-tracker.md共 1 个版本