How can I check out a GitHub pull request with git?

To fetch a remote PR into your local repo,

git fetch origin pull/$ID/head:$BRANCHNAME

where $ID is the pull request id and $BRANCHNAME is the name of the new branch that you want to create. Once you have created the branch, then simply

git checkout $BRANCHNAME

For instance, let’s imagine you want to checkout pull request #2 from the origin main branch:

git fetch origin pull/2/head:MASTER

See the official GitHub documentation for more.

Leave a Comment