Attach a Pull Request to an Existing GitHub Issue

GitHub users may have this experience: after reporting an issue for a project on GitHub, you suddenly found a solution to fix it. Then you want to attach a pull request to this issue, but by the time this article is written, GitHub does not provide a web interface to attach a pull request to an issue. However, no such web interface does not mean it’s impossible — a command line tool called hub could help you out.

Let’s suppose that the project to which you submit the issue is called “test-repo”. The issue is Issue #1. The issue may look something like this:1

You have forked this repo, and you have committed some modification in a branch “my-changes” and pushed them to your repo.2

Now let’s convert this issue to a pull request.

First follow the installation instructions on hub project page to install hub.

Then clone your fork to your local directory if you have not done so. Say your local copy of the repo is at /home/user/test-repo. Switch your working directory to the git repo directory:

cd /home/user/test-repo

Then setup your GitHub token for this repo. After the setup, use hub command to attach a pull-request to the issue you have submitted:

hub pull-request -i 1 -b ORIGINAL_AUTHOR:master -h YOUR_USER_NAME:my-changes

You will then be asked for your GitHub username and password. The number 1 in the above command means the number of the issue you created. In this example, it’s Issue #1, thus 1 is passed to the -i option.

Now this issue should look like this:3

The pull request is now successfully attached to the issue.

7 thoughts on “Attach a Pull Request to an Existing GitHub Issue

  1. Omar Abdel-Wahab

    This is also possible by using Gub gem.
    When you start working on an issue, you execute ‘gub start 123’ to start working on issue #123. Gub would automatically create a branch for that issue.
    And when you’re done, execute ‘gub finish’ and the issue will be converted to a pull-request. No weird parameters or providing branch full URL, etc.

    1. Alexander Obuhovich

      I think they won’t because if you convert issue into PR and then close PR (for whatever reason), then you’ll loose all conversation on that issue.


Leave a Reply

Your email address will not be published.