Fetching a Github pull request for testing

One of my primary research programs is to use ocean gliders (a type of autonomous underwater sampling vehicle) to monitor ocean conditions on the Scotian Shelf near my home of Halifax, NS. As part of that work, I have been exploring ways to build a pipeline for converting the raw data into a consistently-formatted netCDF file with all the relevant data and metadata. I recently starting learning some python, with the goal of using the pyglider toolbox developed by my colleague Jody Klymak as part of his C-PROOF project.

The development of pyglider is being done through the classical “fork and pull request” methodology, with the main or “upstream” repository residing in the C-PROOF organization, my own development happening on a fork at my DFOglider repo, and Jody’s work being done on his own fork.

Recently, Jody created a PR to add functionality that I had requested, and asked me to “review” it. I realized that this was the first time I needed to pull and test a PR originating from someone else’s fork, to a repo that I also have forked. How to do this?

As is often the case, a bit of googling and a stackoverflow answer gave the answer. For my case, because I was operating on a fork, I had to specify the reference to the upstream repo, as:

$ git fetch upstream pull/5/head:enh-sea021

which grabs the version associated with the PR and saves it to a local branch called enh-sea021 (which has the same name as Jody’s branch, but it doesn’t have to). I can then switch to that local branch with:

$ git checkout enh-sea021


Related Articles