Skip to main content

Command referencegh pr checkout

gh pr checkout command (Linux & Windows / GitHub CLI)

Linux & WindowsGitHub CLIgitbeginner

What it does

Check out a pull request locally as a branch so you can build, test, or review the changes. When people search for gh pr checkout, they usually want practical GitHub CLI flags, safe examples, and how this subcommand fits everyday PR and repo workflows on Linux, Windows, and macOS. Syntax, options, and copyable examples are below.

Check out a pull request locally as a branch so you can build, test, or review the changes.

Syntax

gh pr checkout {<number> | <url> | <branch>} [flags]

Common options

Flag / optionMeaning
numberPull request number.
--recurse-submodulesUpdate submodules after checkout when needed.
--detachCheck out in detached HEAD state.
--forceReset the local branch to match the pull request tip.

Practical examples

Checkout by number

gh pr checkout 123

Fetches the PR head and switches to a local branch for it.

From URL

gh pr checkout https://github.com/OWNER/REPO/pull/123

Works from a copied pull request URL.

Force refresh

gh pr checkout 123 --force

Resets the local PR branch to the latest remote head.

Common mistakes

  • Checking out with uncommitted local changes that conflict.
  • Reviewing on a stale local branch without `--force` or a fresh fetch.

FAQ

What does gh pr checkout do in GitHub CLI?

Check out a pull request locally as a branch so you can build, test, or review the changes.

Does gh pr checkout work on Windows and Linux?

Yes. The GitHub CLI (`gh`) runs on Linux, Windows, and macOS with the same subcommand syntax after you authenticate with `gh auth login`.

What is a practical gh pr checkout example?

Try `gh pr checkout 123` — Fetches the PR head and switches to a local branch for it.

Do I need a token in the command line for gh pr checkout?

Prefer `gh auth login` so credentials stay in the system keyring or secure storage. Avoid pasting personal access tokens into shell history.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.