Fetching GitHub pull requests with git

Published on 02 Jun 2021

I often need to fetch a pending Pull Request (PR) from GitHub in order to try a project locally before merging the PR, and although I manage to find the commands in my history, I never remember the commands.

It's rather simple, given that the remote named origin is the one from GitHub, 1234 is your PR number (from GitHub URL, or PR title) and that you want to fetch it under a branch named custom_feature:

git fetch origin pull/1234/head:custom_feature
git checkout custom_feature

I hope I'll remember now!