git,

How to checkout Git Pull Requests

Apr 18, 2022 · 1 min read · Post a comment
How to checkout Git Pull Requests

Checking out Git PR’s on your local machine it’s not so uncommon practice, especially if you wanna test things out before they are merged into the main branch or any other branch that could screw your environment easily that you might care of. Let’s see how is done from the CLI.

Prerequisites

  • Git

From the Terminal / CMD

Step 1. Open Terminal, fetch the Pull Requests and create a new branch on the fly.

git fetch origin pull/<PR_ID>/head:<SOME_BRANCH_NAME>

Example:

git fetch origin pull/136/head:main

Step 2. Now, checkout to the new branch.

git checkout <SOME_BRANCH_NAME>

Step 3 (Optional). If you want to push the local branch to the remote repo, run:

git push origin <SOME_BRANCH_NAME>

Using the GitHub CLI

Step 1. List all pull requests.

gh pr list

Step 2. Checkout a PR.

gh pr checkout 136

Conclusion

If you wanna see more, check the following official GitHub Checking out pull requests locally docs. On a side note, follow our official channel on Telegram.