Create or update a pull request (or merge request) for the current branch following the PR format defined in CLAUDE.md. Supports both GitHub and GitLab.
When to use
- •After committing changes to a feature branch and ready for review.
- •When updating an existing PR/MR description after changes.
- •When creating a draft PR/MR for early feedback.
When NOT to use
- •On the main/master branch. PRs are for feature branches.
- •When there are uncommitted changes. Use
/commitfirst. - •When there are no commits ahead of the base branch.
Arguments
This skill accepts optional arguments after /pr:
- •No arguments: create a new PR/MR.
- •
--draft: create as a draft PR/MR. - •
updateor an existing PR/MR number: update the title and description of an existing PR/MR.
Steps
- •Detect the git platform and CLI tool:
- •Run
git remote get-url originto get the remote URL. - •If the URL contains
github.com, usegh(GitHub CLI). - •If the URL contains
gitlab(e.g.gitlab.comor a self-hosted GitLab), useglab(GitLab CLI). - •If neither matches, ask the user which platform they use.
- •Verify the CLI tool is installed with
which <tool>. If not installed, stop and tell the user.
- •Run
- •Run
git branch --show-currentto get the current branch name. - •Check if a PR/MR already exists for this branch:
- •GitHub: run
gh pr view --json number,url,state(exit code 0 means it exists). - •GitLab: run
glab mr view(exit code 0 means it exists). - •If a PR/MR already exists and the user did NOT pass
updateor a number, show the existing URL and ask whether to update it or stop.
- •GitHub: run
- •Detect the base branch:
- •GitHub: run
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'. - •GitLab: run
glab repo view --output jsonand extract the default branch. - •If both fail, run
git remote show originand look for "HEAD branch". - •Last resort: fall back to
mainormasterbased on what exists locally.
- •GitHub: run
- •Run
git fetch originto ensure the remote is up to date. - •If the project has tests, lint, or build commands, run them to verify the changes pass before pushing. If they fail, stop and tell the user.
- •Rebase on the base branch before pushing:
- •Run
git rebase origin/<base>. - •If there are conflicts, stop and tell the user to resolve them manually.
- •Run
- •Run
git log --oneline origin/<base>..HEADto see all commits that will be in the PR. - •Run
git diff origin/<base>...HEAD --statto see which files changed. - •Run
git diff origin/<base>...HEADto understand the actual changes. - •Push the branch to the remote:
- •Run
git rev-parse --abbrev-ref @{upstream}to check for a tracking branch. - •If no upstream exists, push with
git push -u origin <branch>. - •If upstream exists but is behind, push with
git push.
- •Run
- •Build the PR/MR title and description following the format below.
- •Create or update the PR/MR:
- •Create (GitHub):
gh pr create --title "<title>" --body-file <tmpfile>. Add--draftif requested. - •Create (GitLab):
glab mr create --title "<title>" --description "$(cat <tmpfile>)". Add--draftif requested. - •Update (GitHub):
gh pr edit <number> --title "<title>" --body-file <tmpfile>. - •Update (GitLab):
glab mr update <number> --title "<title>" --description "$(cat <tmpfile>)". - •Always write the description to a temp file first and use
--body-file(GitHub) or read from it (GitLab) to avoid shell escaping issues with multi-line content. - •Clean up the temp file after the command succeeds.
- •Create (GitHub):
- •Show the PR/MR URL when done.
PR Title
- •Clear, specific summary of what the PR accomplishes.
- •Describe the outcome, not the process.
- •Use conventional commit style when it fits:
type(scope): subject. - •When a ticket ID is available in the branch name, prefix it:
TICKET-ID: description. - •Max 70 characters.
Good: feat(auth): add SSO login with Google and GitHub providers
Bad: update auth, fix stuff, changes
PR Description
Template detection
Before generating the description, check if the repo has a PR/MR template:
- •GitHub: look for
.github/PULL_REQUEST_TEMPLATE.mdor.github/PULL_REQUEST_TEMPLATE/directory. - •GitLab: look for
.gitlab/merge_request_templates/directory or amerge_request_template.mdat the repo root.
If a template exists, use it as the base structure and fill in the sections with the actual changes. If no template exists, use the default structure below.
Default structure
Scale the description to the size of the PR:
Small PR (1-2 commits, single concern): A short paragraph explaining what changed and why. No section headers needed.
Standard PR (multiple commits or files): Use this structure:
## What One paragraph explaining what changed and why. A reviewer reading only this paragraph should understand the full picture. ## How Key implementation decisions, trade-offs, and anything non-obvious. Skip trivial details the diff already shows. ## Testing How the changes were verified. Include commands, screenshots, or steps to reproduce.
Add a ## Breaking changes section only if there are breaking changes, with migration steps.
Description rules
- •Wrap at 72 characters.
- •Be concise and direct. No filler prose.
- •Use bullet points for lists.
- •Do not include
Co-authored-bylines.
Rules
- •Always detect the git platform from the remote URL. Never assume GitHub or GitLab.
- •Always detect the base branch dynamically. Never hardcode it.
- •Always rebase on the base branch and push before creating the PR/MR.
- •Always check for an existing PR/MR before attempting to create one.
- •Always check for repo PR/MR templates before generating the description.
- •Always write the body to a temp file to avoid shell escaping issues.
- •If the required CLI tool (
ghorglab) is not installed, stop and tell the user. - •If there are no commits ahead of the base branch, say so and stop.
- •If rebase has conflicts, stop and tell the user. Do not force push or skip conflicts.
- •Do not merge the PR/MR. Only create or update it.
Related skills
- •
/commit- Create semantic commits before opening a PR. - •
/checks- Monitor CI/CD pipeline status after pushing. - •
/review- Review a PR/MR before merging.