Convert GitHub issues into pull requests from the command line

Today I learned how to convert an issue on GitHub directly into a pull request from the command line. This is great because, creating a pull request from within GitHub automatically creates a new issue in the tracker, in addition to the open issue my pull request addresses. In directly converting the original issue into a pull request, no second issue is created and I don’t have to remember to find and close the original issue when my pull request is merged.

It is possible to pull off this amazing feat using Hub. The following steps cover how I set this up on my Mac (other platforms will differ):

1. From Terminal, I installed Homebrew so that I could use the easiest method of installing Hub:

$ ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”

2. Install Hub:

$ brew install hub

3. Create an alias for Hub so that I can use it with the keyword ‘git’. Do this by placing the following command in .bash_profile (I had to create this file as I didn’t already have it):

eval “$(hub alias -s)”

4. Open a new Terminal window so that my new Hub alias is recognised.

5. Now, to turn an existing issue in the main project repository into a pull request from a branch within my fork, I checkout the branch that I want to open the pull request for, and enter this into Terminal:

$ git pull-request https://github.com/protalk/protalk/pull/65

In the Hub documentation, it shows that you should be able to achieve the same result using:

$ git pull-request -i 65 (65 is the issue number)

But I found this didn’t work for me, and kept getting ‘Error creating pull request: Unprocessable Entity (HTTP 422)’. Using the URL to the issue worked like a charm and I was delighted to see that the issue on GitHub had been converted into a pull request with my code attached.

I am told it is possible to reference an issue when opening a pull request from within GitHub. This is done by simply quoting the issue number after a hash symbol: ‘#65′ GitHub automatically converts this into a link to the issue. The downside here is that, as far as I know, a new issue is still created for the pull request although the two issues are now linked.

The bonus with Hub is that a second issue is not opened in the issue tracker (as the open issue is itself converted into a pull request) and I can open the pull request directly from the command line.

There are many more things one can do with Hub, just check out their readme on GitHub for some examples or enter ‘hub help’ on the command line once you’ve got it installed.

Tagged with: , , ,
Posted in News

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>