NOTE: The day after writing this, I made it better
After some setup, I can create a GitHub PR with two commands in the terminal: Entering
pr at the command line followed by
:x in Vim. After that I’m staring at the webpage for the PR in my browser.
Want to do the same?
First, install Hub for GitHub. With Homebrew it’s as simple as
$ brew install hub. You’ll also want to follow the simple instructions to alias
hub. In effect this just gives
git some extra powers.
Now you can type
$ git pull-request -b develop -o which will:
- Prompt you to enter a message for the PR in whatever editor you’ve told Git to use
- Open the webpage for the newly created PR in your browser
But who wants to type that much? The logical next step is to make a shell function so you can just type
pr. In Fish, it looks like this:
function pr set targetbranch 'develop' if test -n "$argv" set targetbranch $argv end git push; and git pull-request -b $targetbranch -o end
Now creating PRs into
develop is as simple as
$ pr and making PRs into
my-big-feature can be done with
$ pr my-big-feature. And with Fish’s autosuggestions you likely won’t even have to type more than a letter or two of your target branch’s name.
One way this could be better is if the URL for the PR page on GitHub could be copied to my clipboard so I could easily paste it into my team’s Slack channel. In fact, the only reason I want to open the PR page at all is so that I can grab its URL. It doesn’t seem like the
pull-request command has a way to just give me the URL. Let me know if I missed that. But since this process ends with me looking at the page I want to share it just takes a quick
⌘L ⌘C to get the URL on my clipboard. Not too shabby.