Checking Out Pull Requests Locally


Sometimes, when someone sends you a pull request from a fork or branch of a GitHub repository, you may want to merge it locally to resolve a merge conflict or to test and verify the changes on your local computer before merging on GitHub. This document describes the process quite well and I have managed to summarize and condense the instructions into a small bash function that can be reused for any GitHub repository:

function fetchpr() {
  pullid=$1
  branch="pr-${pullid}"
  git fetch origin pull/$pullid/head:$branch
  git checkout $branch
}

You can reuse the function by putting it into the likes of your .profile.

Let’s demonstrate with a simple example. Imagine there exists a rather stale pull request https://github.com/org/repo/pull/4585 pending on your org/repo repository. If you want to check out this pull request locally to resume work on it, you could do the following:

cd path/to/repository/directory
fetchpr 4585

You will have the pull request as a local branch under pr-4585.

Misagh Moayyed

Related Posts

CAS 6.2.0 RC4 Feature Release

...in which I present an overview of CAS 6.2.0 RC4 release.

CAS 6.2.0 RC3 Feature Release

...in which I present an overview of CAS 6.2.0 RC3 release.

Apereo CAS - Bootiful CAS Client

Easy to use CAS Client

CAS Vulnerability Disclosure

Disclosure of a security issue with the CAS software.

CAS 6.2.0 RC2 Feature Release

...in which I present an overview of CAS 6.2.0 RC2 release.

Apereo CAS - Authentication Handler Resolution

Learn how to resolve and select authentication handlers based on configurable and flexible filtering criteria.

CAS Vulnerability Disclosure

Disclosure of a security issue with the CAS software.

Apereo CAS - SAML2 Metadata Overrides

Learn how to manage SAML2 service provider registrations in CAS and override metadata artifacts on a per-application basis.

Apereo CAS - Managing Configuration Metadata

Learn how to manage CAS configuration and properties using Spring Boot Configuration metadata.

CAS 6.2.0 RC1 Feature Release

...in which I present an overview of CAS 6.2.0 RC1 release.