Get the FREE Ultimate OpenClaw Setup Guide →

gh-pr-checkout

Scanned
npx machina-cli add skill dceoy/github-cli-agent-skills/gh-pr-checkout --openclaw
Files (1)
SKILL.md
2.1 KB

GitHub PR Checkout

When to use

  • The user asks to check out a PR locally.
  • You need to test or review PR changes on your machine.
  • Switching between PRs for code review.

Inputs to confirm

  • PR number, URL, or branch name.
  • Custom local branch name (optional).
  • Target repo if not current (--repo OWNER/REPO).

Workflow

  1. Verify auth and git status:

    gh --version
    gh auth status
    git status
    
  2. Check out the PR:

    gh pr checkout 123
    gh pr checkout https://github.com/OWNER/REPO/pull/123
    gh pr checkout feature-branch
    
  3. Use options as needed:

    # Custom local branch name
    gh pr checkout 123 --branch my-review-branch
    
    # Force update existing branch
    gh pr checkout 123 --force
    
    # Detached HEAD (no local branch)
    gh pr checkout 123 --detach
    
  4. After checkout, verify:

    git branch --show-current
    git log --oneline -5
    

Examples

# Check out PR #123
gh pr checkout 123

# Check out with custom branch name
gh pr checkout 123 --branch review-feature-x

# Force refresh an already checked out PR
gh pr checkout 123 --force

# Interactive selection from recent PRs
gh pr checkout

Flags reference

FlagDescription
-b, --branchLocal branch name (default: head branch name)
--detachCheckout with detached HEAD
-f, --forceReset existing local branch to PR state
--recurse-submodulesUpdate submodules after checkout

Notes

  • Without arguments, interactively select from recent PRs.
  • The --force flag is useful when PR has been updated.
  • Use --detach for quick inspection without creating a branch.

References

Source

git clone https://github.com/dceoy/github-cli-agent-skills/blob/main/skills/gh-pr-checkout/SKILL.mdView on GitHub

Overview

gh pr checkout pulls a pull request into your local environment using the GitHub CLI. It accepts a PR number, URL, or a branch name and can create a named local branch or operate in detached HEAD mode. This makes reviewing and testing PR changes on your machine fast and convenient.

How This Skill Works

First, verify authentication and that your git status is clean. Then run gh pr checkout with a PR identifier or URL; you can add --branch to name the local branch, --force to refresh an existing branch, or --detach to inspect without creating a branch. After checkout, confirm your current branch and review recent commits with git commands.

When to Use It

  • You need to check out a PR locally to review changes on your machine.
  • You want to test or run the code in a PR before merging.
  • You need to switch between multiple PRs quickly during code review.
  • You have a PR URL or number and want to open it in a local branch for work.
  • You want to inspect a PR without creating a local branch (detached HEAD).

Quick Start

  1. Step 1: Ensure gh is installed and authenticated in your environment.
  2. Step 2: Run gh pr checkout with a PR number, URL, or branch name.
  3. Step 3: Verify your current branch and recent commits with git commands.

Best Practices

  • Verify gh is authenticated and you are in the correct repository with git status before checkout.
  • Use --branch to name your local branch for easier switching and context.
  • Use --detach only when you want a quick look without a local branch.
  • After checkout, run git branch --show-current and git log --oneline to confirm the state.
  • If the PR is updated, use gh pr checkout --force to refresh your local copy.

Example Use Cases

  • gh pr checkout 123
  • gh pr checkout 123 --branch review-feature-x
  • gh pr checkout https://github.com/OWNER/REPO/pull/123
  • gh pr checkout 123 --detach
  • gh pr checkout 123 --force

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers