| name | open-pr |
| description | Compare branch against main and open a pull request via gh CLI |
open-pr
Goal
Compare the current branch against main, generate a short description of the changes, and open a pull request using the gh CLI.
Behavior
When invoked:
-
Verify gh prerequisites:
gh auth status
If not authenticated, stop and instruct the user to run gh auth login.
-
Identify the current branch:
git branch --show-current
-
Fetch latest base branch (defaults to main unless the user specifies otherwise):
git fetch origin <base-branch>
-
Check for unpushed commits:
git log origin/$(git branch --show-current)..HEAD --oneline
If unpushed commits exist, warn the user and ask whether to push first.
-
Compare current branch vs base branch:
Commits ahead
git log origin/<base-branch>..HEAD --oneline
Changed files summary
git diff origin/<base-branch>..HEAD --stat
-
Categorize changes from commit messages:
| Category | Patterns |
|---|
| Features | feat: |
| Fixes | fix: |
| Docs | docs: |
| Refactoring | refactor: |
| Other | chore:, test:, style:, perf: |
-
Generate PR title:
Use the most significant category as prefix (e.g. feat:, fix:) followed by a concise summary derived from commit messages. If the branch name is descriptive, use it as a fallback.
-
Generate PR body:
A short description covering:
- What changed (summarized from commit messages and file stat)
- Files changed count and key paths affected
Format:
## Summary
<2–3 sentence description of changes>
## Changed Files
<list of key files/paths>
-
Open the pull request:
gh pr create \
--base <base-branch> \
--head $(git branch --show-current) \
--title "<generated-title>" \
--body "<generated-body>"
-
Report the PR URL so the user can review and merge.
-
If Git remote differs from the default origin, detect and use the correct remote:
git remote
Notes
- The base branch defaults to
main but can be overridden by the user (e.g. develop, release/x.y).
- If the branch has no commits ahead of the base branch, stop and inform the user — there is nothing to PR.
- If there are merge conflicts with the base branch, report them and do not proceed.