Reviewing Pull Requests Locally

When reviewing a pull request, I often like to pull the code and actually run it, because sometimes code that looks fine at first glance doesn't actually work. If you're reviewing PRs on GitHub, then you can use the GitHub CLI to quickly check out a PR locally, but that doesn't really help out for Codeberg/Forgejo. It turns out there's a special ref created for PRs: refs/pull/<PR>/head, where <PR> is the actual number of the PR you want to checkout. To make use of it, you just have to fetch it first:

git fetch origin refs/pull/123/head:pr-review

In this example, I'm assuming origin is the remote for Codeberg/Forgejo, 123 is the number of the PR in question, and pr-review is the name of the local branch where you'd like to inspect the code. Once you've fetched it, you just have to switch over to it:

git checkout pr-review

This trick also works on GitHub, so you don't have to install the CLI if you don't want to, at least not for this functionality.