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:

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:

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.

  • I’m pleased to discover that it’s possible to convert an issue into a pull request. Hopefully GitHub adds this feature to their UI one day.

    • Thanks.

    • 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.

  • Thanks! This really helped a lot. 🙂
    Oh, and yea, just as @davidchambers:disqus said, I hope they add this to their UI someday.

  • Johnny Goodman

    Thanks for writing this up. I’ve used it twice. 🙂

  • chase

    I think it’s now possible to just add a link to the issue and the two will be associated

  • 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.