| name | pr |
| description | Create a pull request for the current branch using `gh`. |
Create Pull Request
Create a pull request for the current branch using gh.
Current State
- Branch: !
git branch --show-current
- Commits on branch: !
git log main..HEAD --oneline 2>/dev/null || git log master..HEAD --oneline
- Changed files: !
git diff main...HEAD --stat 2>/dev/null || git diff master...HEAD --stat
Steps
1. Detect repo and base branch
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
BASE=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@refs/remotes/origin/@@' || echo "main")
Use $REPO for all gh commands. Use $BASE wherever a base branch is needed.
2. Gather context
- Review the commits and changed files above.
- Check if the branch is associated with a GitHub issue (look at branch name,
commit messages, or recent context for an issue number).
3. Study repo PR style
- Fetch the 5 most recently merged PRs in the repo:
gh pr list --repo $REPO --state merged --limit 5 --json title,body
- Note the tone, length, and structure of titles and descriptions.
- Match that voice and style in the PR you create.
4. Detect PR template
Check for a PR template:
cat .github/PULL_REQUEST_TEMPLATE.md 2>/dev/null || cat .github/pull_request_template.md 2>/dev/null || echo "NO_TEMPLATE"
If a template exists, fill it out with the relevant information from the
changes. If no template exists, write a brief, factual body.
5. Push the branch
Run git push -u origin HEAD.
6. Create the PR
Use gh pr create --repo $REPO with:
- Title: Short, direct summary of the change (under 70 chars).
- Body:
- If a PR template was found, use it filled out appropriately.
- Otherwise, write a brief, factual summary of what changed and why.
- If there is an associated issue, include a closing reference on its own
line at the top of the body using the format the repo's issue tracker
expects (e.g.,
Fixes #<number> or Closes #<number>).
Keep the description concise. Just state what was done. No filler.
CRITICAL: Ensure no Co-Authored-By lines appear anywhere in the commits
or PR body. Sole authorship policy — no AI attribution.
7. Done
Print the PR URL for the user.