-
Determine the base branch by running:
git remote show origin
Look for the "HEAD branch" line to identify whether the default branch is master or main. Use that as the base branch.
-
Ensure the current branch is pushed to origin. If it does not already track a remote branch, push with:
git push -u origin HEAD
-
Gather context for the PR description:
-
Get all commit messages on this branch:
git log <base>..HEAD --oneline
-
Get the full diff of changes:
git diff <base>...HEAD
-
Extract a ticket ID from the current branch name using the pattern [A-Z]+-[0-9]+ (e.g. MCB-29 from ben/MCB-29-add-admin-tool). If a ticket ID is found, prepare a Linear link: https://linear.app/issue/<TICKET>.
-
Generate a PR title — a concise summary of the changes, under 70 characters.
-
Generate a PR description in this format:
## Summary
<1-3 bullet points describing what changed and why>
## Test plan
<bulleted checklist of how to verify the changes>
<Linear ticket link if a ticket ID was found, otherwise omit>
-
Create the PR using gh pr create targeting the detected base branch. Use a HEREDOC for the body to preserve formatting:
gh pr create --base <base> --title "the pr title" --body "$(cat <<'EOF'
## Summary
...
## Test plan
...
https://linear.app/issue/TICKET-123
EOF
)"
-
Enable auto-merge (unless the user passed --no-auto-merge or no-auto-merge as an argument):
gh pr merge --auto --merge
-
Output the PR URL returned by gh pr create.