Fetching GitHub pull requests with git

Published on 2021-06-02 by xarkes

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!