DevOps Zone is brought to you in partnership with:

Lorna Jane Mitchell is a PHP developer, blogger, trainer and evangelist from Leeds in the UK. She is active with phpwomen.org and her local user group PHP North West, and writes for a variety of outlets, including her own blog at lornajane.net. She is an active member of the PHP and open source communities and contributes to the joind.in event feedback project. When she's not at her computer, Lorna enjoys yarn craft, hobby electronics, and her home renovation project. Lorna is a DZone MVB and is not an employee of DZone and has posted 82 posts at DZone. You can read more from them at their website. View Full User Profile

Open a GitHub Pull Request with Hub

12.10.2013
| 5475 views |
  • submit to reddit

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.



Published at DZone with permission of Lorna Mitchell, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)