Convert Github Issue to Pull request

Photo by Harley-Davidson on Unsplash

Convert GitHub Issue to Pull request

The typical difficulty for most GitHub users is to manage 2 cards per task (an Issue and a connected Pull request). It consumes a lot of time and energy to maintain a project, mainly when you create an Issue before you start coding.

TL;DR: hub pull-request attaches a branch to the existing GitHub issue or creates a new pull request: hub pull-request -i <issue number>

The most common steps for new users are:

Instead of having one issue, we have 2. It introduces some problems:

The first problem: The original description and communication located in the “Issue #1”. However, after a developer ask for a review of “Pull request #2”. People comment and continue the discussion in the pull request. It makes a bit harder to find information related to the task later.

The second problem is to keep the state of the original “Issue #1” the same as for “Pull request #2”.

Example: in the project board you moved the “Pull request #2” to ‘Review’ column — please move “Issue #1” to the same column.

The third: you should sync labels, milestones, and assigners. It is not a DRY way.

Example: marked “Issue #1” with a label “blocked” — don’t forget about “Pull request #2”.

My suggestion — use the hub command-line tool instead of Web UI. There are at least several advantages:

Here is a sample workflow of how I convert “Issue #1” to “Pull request #1”:

$ cd <path to repo>
$ git checkout -b 1-change-title
$ git commit -a
$ git push
$ hub pull-request -i 1

Voila, there is no “Issue #1” anymore, but “Pull request #1” goes with the branch 1-change-title attached and the same description and comments. Plus, your GitHub project automatically moves this Issue to the next column (if you have setup column automation).

For GitHub Enterprise users, here is a hint of how to change default domain to custom:

$ git config add hub.host github.jetthoughts.com

If you need to create a fresh new “Pull request” — run hub pull-request without the -i argument.

Check for other hub pull request options available: create a draft pull request, assign reviewers, set labels, and other choices.

Hub authentication

The first challenge to use hub would be authentication. hub would ask for Github user and password, but the** password** is not working.

$ hub pull-request -i 321
github.com username: miry
github.com password for miry (never stored): 

You should use a token instead. Visit Github -> Settings ->Developer settings -> Personal Access tokens via https://github.com/settings/tokens.

Create a new token with at least scopes to access private repos, gist, and write discussion. Use the generated token in prompt for password in the terminal window.

Github token scopes

More details about you can find in the man page.

Summary

Stop creating a separate pull request for each Issue on GitHub. I encourage you to learn more about other commands from hub.

Michael Nikitochkin is a Lead Software Engineer. Follow him on LinkedIn or GitHub.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories.

Refernces

https://hub.github.com/hub-pull-request.1.html