| name | pr |
| description | Create a pull request with intelligent base branch detection. Use when: (1) User says 'create pr', 'make pr', or 'open pr', (2) User wants to create a PR from the current branch, (3) User has finished work on a feature branch and needs a PR. Auto-detects base branch from conversation, git history, or repo default. |
| argument-hint | [target-branch] |
PR Command
Create a pull request with automatic base branch detection from conversation history, git log, or repository default.
Usage
/pr - Create PR with auto-detected base branch
/pr <target-branch> - Create PR targeting the specified branch
Steps
1. Verify Current State
git status
git branch --show-current
Ensure you're on a feature branch (not main/master/develop).
2. Determine Base Branch
Priority order for base branch detection:
- Explicit argument: If
<target-branch> is provided, use it directly
- Conversation context: Search conversation history for mentions of:
- "based on", "branch from", "create branch from"
- PR context or issue references that mention a target branch
- Recent git commands showing branch creation
- Git history: Auto-detect from git log and merge-base
- Repository default: Use the default branch as fallback
Conversation History Check
Search the current conversation for clues about the base branch:
- Look for phrases like "create branch from develop", "based on feature-x"
- Check if user mentioned which branch they started from
- Look for issue/PR context that indicates the target
Git History Detection
git fetch origin
for branch in main master develop staging; do
git merge-base HEAD origin/$branch 2>/dev/null && echo "Found: $branch"
done
Repository Default Fallback
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
3. Check for Existing PR
gh pr list --head $(git branch --show-current)
If PR exists, ask user if they want to view or update it.
4. Analyze Changes
git log origin/<base-branch>..HEAD --oneline
git diff origin/<base-branch>..HEAD --stat
5. Confirm with User
Before creating, confirm:
- Current branch:
<branch-name>
- Target base branch:
<base-branch> (with detection method: "specified", "from conversation", "auto-detected", or "default")
- Commits: Number of commits to include
- Suggested PR title: Based on commits/branch name
6. Push and Create PR
git push -u origin $(git branch --show-current)
gh pr create \
--base <base-branch> \
--title "<title>" \
--body "$(cat <<'EOF'
## Summary
<description>
## Changes
- <change 1>
- <change 2>
## Test Plan
<testing instructions>
EOF
)"
7. Report Result
Display:
- PR URL
- PR number
- Base branch (and how it was determined)
- Head branch
Detection Logic
The command uses this logic to find the base branch:
- User-specified: Highest priority - use the argument directly
- Conversation analysis: Check conversation for branch context
- Git merge-base: Find closest common ancestor with candidate branches
- Default branch: Ultimate fallback using
gh repo view
If detection is ambiguous, ask the user to clarify before creating the PR.
Important Notes
- Never assume main/master without verification
- Always inform user how the base branch was determined
- Verify branch is pushed before creating PR
- Include meaningful PR title and description