Cookbook/Testing GitHub PRs Locally
workflow
8 min

Testing GitHub PRs Locally

github
testing
review

Testing GitHub PRs Locally

Overview

Learn how to test GitHub pull requests locally without merging them into your main branch. This recipe shows multiple methods to safely review and test PR code.

Prerequisites

  • Git installed
  • GitHub CLI (optional but recommended)
  • Clean working directory

Quick Steps to Test a PR Without Merging

1. Ensure clean working directory

git status  # Check for uncommitted changes
git stash   # If needed, stash changes

2. Fetch and switch to the PR

Option A: If you know the PR number (e.g., #123)

git fetch origin pull/123/head:pr-test-branch
git switch pr-test-branch

Option B: Using GitHub CLI

gh pr checkout 123

3. Test the code

# Run your normal build/test commands
npm install && npm test
# or whatever your project uses

4. Switch back to main when done

git switch main

5. Clean up (optional)

git branch -D pr-test-branch

Finding PR Numbers

  • Check the GitHub PR URL: /pull/123
  • Or run: gh pr list

Tips & Best Practices

  • Work in your existing repo directory - Git handles file switching
  • Always stash/commit local changes before switching branches
  • You can switch between branches freely to compare changes: git switch branch-name
  • To update an existing PR branch: git fetch origin pull/123/head:pr-test-branch --force

References

Master Claude Code with Expert Training

These recipes are from our comprehensive 2-day training course. Learn directly from experts and transform your development workflow.