create-pr
Creating a Pull Request
Gather context
Run as one batch:
git status
git fetch origin
gh pr list --head "$(git branch --show-current)" --state open --json number,url,title,baseRefName
ls .github/pull_request_template.md .github/PULL_REQUEST_TEMPLATE.md .github/PULL_REQUEST_TEMPLATE/ docs/pull_request_template.md pull_request_template.md 2>/dev/null
An open PR means updating it — gh pr create fails on a branch that already has one.
Never commit on the default branch. On main or master, create a branch with git switch -c <branch> and tell the user its name. When there is a ticket, start the name with its ID (abc-123-add-invite-status). Only ever create a new branch — switching to an existing one changes which work the PR describes.
Base. An existing PR keeps its baseRefName. Otherwise use the branch this one was cut from — often another open PR's branch or an epic branch, not the default. The candidates are the default branch and every other open PR's head (gh pr list --state open --json headRefName). For each, count git rev-list --count $(git merge-base origin/<candidate> HEAD)..HEAD; the lowest count wins, and ties go to the default. Skip a candidate cut from this branch, where the merge base is HEAD but the tip isn't. If gh fails, use the default branch. The user can name a different one. Then read the work against it: