How to checkout pull request locally?

It has been a few months that I have joined Gutenberg project πŸŽ‰ on the Github platform. Now I can do PR(pull request) review and add a comment if required, or if everything looks good, I can merge it. I started with the PR review. I found that I don’t know how to checkout to PR changes πŸ˜”!

I checked online and found the easiest way to checkout PR is to use Github CLI tool. On Github, If you navigate to the PR. You will see something like this.

Github CLI PR checkout

Command mentioned in the screenshot solves the problem; however, I was curious how can I do the same without the Github CLI tool. After going through the documentation, I found a command as below.

git fetch pull/<PR-ID>/head

After running the above command as you can see that a new branch is fetched (as shown in the below image). Git fetch pull

Now I did git checkout FETCH_HEAD and checked out the same PR.