gh pr checkout

Check out a pull request in git

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


  -b, --branch string        Local branch name to use (default: the name of the head branch)
      --detach               Checkout PR with a detached HEAD
  -f, --force                Reset the existing local branch to the latest state of the pull request
      --recurse-submodules   Update all submodules after checkout

Options inherited from parent commands

      --help                     Show help for command
  -R, --repo [HOST/]OWNER/REPO   Select another repository using the [HOST/]OWNER/REPO format

In use

Using pull request number

You can check out any pull request, including from forks, in a repository using its pull request number

// Checking out a pull request locally
~/Projects/my-project$ gh pr checkout 12
remote: Enumerating objects: 66, done.
remote: Counting objects: 100% (66/66), done.
remote: Total 83 (delta 66), reused 66 (delta 66), pack-reused 17
Unpacking objects: 100% (83/83), done.
 * [new ref]             refs/pull/8896/head -> patch-2
Switched to branch 'patch-2'


Using other selectors

You can also use URLs and branch names to checkout pull requests.

// Checking out a pull request locally
~/Projects/my-project$ gh pr checkout branch-name
Switched to branch 'branch-name'
Your branch is up to date with 'origin/branch-name'.
Already up to date.