TWiStErRob

Quick walkthrough

How to do a PR?

Full process of how I go through a pull request for a GitHub fork.

Many times when you ask for a feature in a GitHub issue, you’re welcomed with:

Can you create a PR please?

… even if it’s a one-character typo. Here’s how I create a PR.

What is a PR?

A Pull Request is request created on GitHub to merge code from one fork of the repository to another. Usually there’s a feature/bug branch in the fork and the PR is made against the master branch —, or wherever their HEAD commit is — in the base repository.

GitHub setup

As easy as pressing Fork button on GitHub.

Checkout

Click the HTTPS link below the clone URL box and then copy the HTTPS clone URL which can be then used to clone a repo:

me@laptop$ git clone https://github.com/me/repo-name.git .
Cloning into '.'...

Immediately after this I go back to the original repository (where I forked from) and repeat the HTTPS link copying and add the remote:

me@laptop$ git remote add -f mint https://github.com/stranger/repo-name.git # -f == immediate fetch
Updating mint
me@laptop$ git remote set-url --push mint DISALLOWED

This is useful if the original repo is active and you want to keep up to date. I call it mint (after the adjective in “mint condition”), because the normal clone operation creates an origin remote, also mint suggests to keep it clean.

me@laptop$ git remote -v # == git remote --verbose show
mint    https://github.com/stranger/repo-name.git (fetch)
mint    DISALLOWED (push)
origin  https://github.com/me/repo-name.git (fetch)
origin  https://github.com/me/repo-name.git (push)

Update remote

stranger-head-branch is usually the master branch and my-pr-branch’s name is highly correlated with what your PR is representing.

me@laptop$ git checkout stranger-head-branch
Switched to branch 'stranger-head-branch'

me@laptop$ git merge mint/stranger-head-branch
Updating abc1230..abc123f
Fast-forward
...

me@laptop$ git checkout my-pr-branch
Switched to branch 'my-pr-branch'

me@laptop$ git rebase stranger-head-branch
First, rewinding head to replay your work on top of it...
Applying: Commit message 1
Applying: Commit message 2
...

Create PR

me@laptop$ git push --all

Upon success just go to the original repo or your fork on GitHub and you should see a Your recently pushed branches: tip with a Compare & pull request button.

Review changes, fill in description and you’re good to go.

Future of a PR

If the repository owners like what you did and it adheres to rules usually defined in CONTRIBUTING.md they’ll merge your PR and you’ll see a Pull request successfully merged and closed message with a Delete branch button next to it. That helps to keep your fork’s working branches to a minimum. Once it’s merged the commits are copied to their repository so it’s safe to delete your branch.

There’s of course the possibility that something goes wrong, like the CI build fails or there’s some modification needed in the PR. In that case make some more commits to your fork, or even rebase or squash commits; then push it to the working branch and the PR will be updated automatically.

Go to top