The first time someone asked me to review their pull request, I opened GitHub in one tab, Slack in another, and realized I had no idea how to actually run their code. I ended up manually cloning their fork, hunting for the branch name, and generally making a mess of my local repo. There had to be a better way.

Turns out there are two — and I've been using both for years now.

The Problem with Code Review

GitHub's web interface works for small diffs. But when you need to actually run the code — test that endpoint, verify the UI fix, debug why tests fail — you need the PR locally.

The default workflow is awkward: message the author for their fork URL and branch name, or click through GitHub's UI to find it. Both are slower than they should be.

What I wanted was: type the PR number, get the code.

Method 1: Git Config (80% of My Reviews)

Add this to .git/config under [remote "origin"]:

fetch = +refs/pull/*/head:refs/remotes/github-pr/*

Now git fetch pulls all PRs:

 * [new ref]   refs/pull/1015/head -> github-pr/1015
 * [new ref]   refs/pull/1020/head -> github-pr/1020

Checkout any PR:

git checkout github-pr/1015

You're now on the exact commit from the PR. Yes, it's a detached HEAD. Yes, that's mildly annoying if you want to push changes. But for reading code and running tests — which is most of my reviews — I don't care. It works on any machine with Git, including ancient servers where installing new tools isn't an option.

The detached HEAD is actually a feature sometimes. It stops me from accidentally committing to someone else's PR when I'm just exploring.

Method 2: GitHub CLI (When I Need Power)

Sometimes you need more. Maybe you want to push fixes back to the PR — fix a typo, push it, they merge, everyone's happy. Or maybe you want proper branch tracking.

Install the GitHub CLI, authenticate once with gh auth login, then:

gh pr checkout 1015

This sets up proper branch names, remote tracking, and handles forks automatically. Push works because gh configured the upstream for you.

I also use gh pr list to scan open PRs without loading GitHub's increasingly slow interface. Then I checkout the interesting ones.

The Annoying Part

It's another tool to install. Another thing that can break when SSH'd into a server. Another auth token to manage. When gh works, it's great. When it doesn't, you're debugging OAuth flows instead of reviewing code.

Also, gh auto-updated once and broke my shell integration for two days. Not fun when you're trying to ship.

My Actual Workflow

Quick review — just reading and testing:

git fetch
git checkout github-pr/420
go test ./...
git checkout main

Review where I need to fix something:

git checkout main  # start clean
gh pr checkout 420 --branch review-420
# ... fix the bug ...
git commit -am "fix: handle nil pointer"
git push  # pushes to their PR automatically
gh pr review 420 --approve

The CLI shines when you're making changes. For just reading code? Overkill.

The Hidden Cost Nobody Mentions

Here's an edge case I hit once: the git config method fetches ALL PRs on every fetch. If you're in a repo with 500 open PRs, that's a lot of refs. Your git fetch slows down. git branch -a becomes unreadable.

In that case, use gh. It checks out only what you need.

For normal repos with 20-50 PRs? Who cares. Fetch them all.

Meta description: Learn how to checkout GitHub pull requests for local testing. Two practical methods: a quick git config hack for fast reviews, and GitHub CLI when you need to push changes back.

FAQ

Q Does the git config method work with private repositories?
A Yes, as long as your SSH key or token has access to the repo. The fetch happens over your existing Git authentication.
Q Can I push changes back with the git config method?
A Not directly — you're in a detached HEAD state. Switch to the GitHub CLI method if you need to push fixes to the PR.
Q What if the PR is from a fork in a different organization?
A Both methods handle forks automatically. The git config method fetches refs/pull/* which includes cross-repo PRs. gh pr checkout resolves the fork remote for you.
Q Does gh pr checkout work with GitHub Enterprise?
A Yes, run gh auth login --hostname your-ghe-instance.com first to authenticate against your Enterprise server.
Q Why does git fetch slow down with the config method?
A Git fetches all PR refs. If your repo has 500+ open PRs, that's a lot of refs to download. Use gh for large repos — it checks out only what you need.
Asaduzzaman Pavel

About the Author

Asaduzzaman Pavel is a Software Engineer who actually enjoys the friction of a well-architected system. He has over 15 years of experience building high-performance backends and infrastructure that can actually handle the real-world chaos of scale.

Currently looking for new opportunities to build something amazing.