Tuesday, 6 April 2021

Preparing for a Github PR

This is a note about preparing a pull request (PR) for a Github repository. As much as anything, it’s to stop me having to page back through my lab notebook to find out how I did it last time …

The repo I want to raise the PR on is quux/foo, which I’ve cloned locally. I’ll call that the target repo, and the local clone the local repo.

The change I’ve made is in my local branch v42.0.0 (which corresponds to a parent tag), checked in at commit 41a28d6.

The first step is to fork the repo on Github. In my fork, under the Code button, copy the URL - in this case, git@github.com:simonjwright/foo.git. I’ll call this the forked repo.

Then, in my local repo (which was cloned from the target),

git remote add sjw git@github.com:simonjwright/foo.git
git fetch --all

(you probably want to use your own initials rather than mine!)

Now check out the forked repo in a local branch - I’ll call it sjw, though I have to admit that having the same name as the name I’ve used for the remote could be confusing.

git checkout -b sjw sjw/master

(may not be master, given recent changes to Github policy).

Make a new branch, to contain just this change:

git checkout -b my-change

(probably best to choose a more meaningful name).

Cherry-pick the commit you want to use for the PR:

git cherry-pick 41a28d6

Push this branch to Github:

git push --set-upstream sjw my-change

Now, go to the forked repo on Github; you should be invited to raise a PR on the target repo.

No comments:

Post a Comment