Well, use a script

Let’s say I want to test this PR locally, meaning I need to fetch the code locally to my laptop. All I need is the URL and nothing more.

Clone the repository locally (if you haven’t done it already), change into this directyory and then run the script:

$ testpr https://github.com/redhat-appstudio/managed-gitops/pull/177


remote: Enumerating objects: 202, done.
remote: Counting objects: 100% (202/202), done.
remote: Compressing objects: 100% (129/129), done.
remote: Total 202 (delta 68), reused 187 (delta 67), pack-reused 0
Receiving objects: 100% (202/202), 443.32 KiB | 1.42 MiB/s, done.
Resolving deltas: 100% (68/68), completed with 7 local objects.
From github.com:redhat-appstudio/managed-gitops
 * [new ref]         refs/pull/177/head -> test-pr-177
Switched to branch 'test-pr-177'

The testpr script is very simple (really simple) and looks like this:


# https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally

REMOTE="origin" # <-- change this if you use different remote target
if test -z "$URL"; then
	echo "Use: testpr <GITHUB PR URL>"
    exit 1

ID=$(echo "$URL" | sed -e 's/.*\/\([0-9]*\)$/\1/')


if git fetch "$REMOTE" pull/"$ID"/head:"$BRANCHNAME"; then
	git checkout "$BRANCHNAME"
	echo "Something is wrong"
    exit 1

Just put it somewhere in your $PATH env, so you can execute it from everywhere in your shell. Feel free to modify it, especially if you use different REMOTE. In my case, I use origin to refer to the upstream project. Some other folk, do it the otherway around: the use upstream remote to refer to upstream.