Check for Existing PRs Before Creating

lesson workflow archived workflow/check-existing-prs.md View on GitHub

Check for Existing PRs Before Creating

Rule

Always check for existing PRs addressing the same issue before creating a new PR.

Context

When investigating an issue and planning to create a PR to fix it.

Detection

Observable signals indicating you should check first:

Pattern

Check before creating:

# Search by issue number and topic
gh pr list --state open --search "605 in:body"
gh pr list --state open --search "mcp config"

# Also check GitHub's issue -> closing PR metadata
gh api graphql \
  -f owner=OWNER \
  -f repo=REPO \
  -F issue=605 \
  -f query='query($owner:String!, $repo:String!, $issue:Int!) {
    repository(owner:$owner, name:$repo) {
      issue(number:$issue) {
        closedByPullRequestsReferences(first:10) {
          nodes { number title url state }
        }
      }
    }
  }' \
  --jq '.data.repository.issue.closedByPullRequestsReferences.nodes[]'

# Do not use /issues/605 --jq '.pull_request'; that only says whether 605 is itself a PR.

# If found: Review and coordinate
# If not found: Proceed with new PR
git checkout -b fix-issue-605
gh pr create

Outcome

Following this pattern leads to:

Time saved: Finding existing PR takes 30 seconds vs hours of duplicate work.

Related

Match Keywords

gh api graphql