Create a Pull Request using Command Line Tool, Hub
GitHub is a decent version control repository for collaboration. To work together, GitHub suggests a flow, including to make a pull request. Here is the definition of pull request from “About pull requests” GitHub.
Pull requests let you tell others about changes you’ve pushed to a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before the changes are merged into the repository.
General way to make a pull request is that you first change the code to suggest in your branch, push your branch, and click a create pull request button in the GitHub.
Image from “Creating a pull request”
This is not a complicate. However, you need to open the web browser to do it. For command line lovers, GitHub made a commland-line wrapper for git
, which is called hub
(https://hub.github.com).
After this, you can run GitHub commands in addition to normal git
commands.
Without opening a web browser, now we can make a pull request using a command line.
Everything works well. However, I think one thing is missing. When you run git pull-request
, an editor, such as vi
, will be opened, and you need to type a pull request message. When you use a web browser, that is the same message from the last commit if you made only one commit change. Since that is the most common case, I don’t want to type again every time.
Fortunately, hub
allows us to set a message parameter when run the command.
So, only left thing is to get the last commit message. We can get it using a below command.
To sum up, we can run below command to create a pull request which having a pull request message from the last commit without opening a web browser and an editor.
Of course, alias
is always our best friends.