Open a GitHub Pull Request with Hub

Both in my professional life and in my personal life as an open source project lead, I spend a lot of time working with git in general, and GitHub in particular. GitHub publishes a command line tool called hub, which is a more convenient way than the website for doing a few specific tasks and in particular I’ve been using it more and more for opening pull requests.

The basic workflow is to create a branch, add your changes, and then push it to GitHub (I’m pushing to my origin, I’m not sure what happens if you’re pushing to somewhere else but if you know then please add a comment). Then you have a few options:

  • Create a pull request against origin/master (this is the default):
    hub pull-request
  • Create a pull request against another repo, you’d probably use this for open source or any other situation where you are pushing to a fork but requesting a pull against an upstream repo; use the -b switch and the format owner:branch:
    hub pull-request -b joindin:master
  • Create a pull request against a branch called something other than “master”:
    hub pull-request -b develop
  • Create a pull request against something else entirely! The argument is in the format owner/repo:branch for that

It’s fairly common also to alias your “hub” command to “git”, which gives you all your existing git functionality with a few special GitHub-aware features like the pull request command you’ve seen above. I personally don’t have it set up this way, but if you do then you can simply s/hub/git/ in the above examples.

If the changes you want to pull request aren’t in “the branch named what I’m currently on, in the origin repo” then you can use the same format of arguments with the -h switch also. Whether you prefer to work from commandline, or you’re looking to wrap up some of your process in a scriptable way, hub could be pretty handy.

One thought on “Open a GitHub Pull Request with Hub

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.