gh pr checkout Switch to the branch of a pull request
Fetches the code from a pull request and checks it out as a local branch, so you can run or review it. It works for branches in forks as well.
Synopsis
gh pr checkout {NUMBER | URL | BRANCH} [FLAGS]
Common options
| Option or form | What it does |
|---|---|
-b, --branch NAME | Local branch name to use |
-f, --force | Reset the local branch to match the pull request |
--detach | Check out without creating a branch |
--recurse-submodules | Also update submodules |
Examples
gh pr checkout 42
Switched to branch 'feature/search'
gh pr checkout https://github.com/octocat/Hello-World/pull/42
gh pr checkout 42 --branch review-42
gh pr checkout 42 --detach
Notes
- Run it in a clone of the repository. gh sets up tracking so git pull brings new commits from the author.
- If you have local changes, commit or stash them first.
- Without the GitHub CLI you can use git fetch origin pull/42/head:pr-42.
See also
Last reviewed 2026-10-09.