Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

GitHub Merge Button From CLI

DZone's Guide to

GitHub Merge Button From CLI

GitHub is the lifeblood for DevOps, but strangely, some features work better from the GUI than they do from the developers' favorite stomping grounds, CLI. Read to create the CLI-equivalent to the GUI "merge" button.

· DevOps Zone
Free Resource

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

github-merge-cliIt’s no fun to have to clean up git history after a botched command line merge of a GitHub pull request. I love to live life in the shell, and I don’t want to open a new browser tab just to click The Merge Button, so sometimes I’m stubborn and I don’t. And sometimes I waste a lot of time cleaning up the mess that happens when I try to do all of that with an outdated master branch.

With some prodding and direction from my good friend pengwynn, I put together a script based on the new-to-me Merge Button API Route. Check out the installation and usage instructions below to get set up.

Installation

A nice thing you may not have known about the git command line is that it will automatically alias tools in your path titled git-foo such that they’ll just work when you invoke them as proper git subcommands as in: git foo. So simply download/copy the shell script from my dotfiles, name it git-merge-pr, and copy it into your $PATH and walah, you can invoke it as: git merge-pr.

Usage

Call it with -h for proper usage. The script takes a single, optional argument; either the name of the branch you want to merge in, or the pull request number. If you don’t pass in an argument, it assumes you’ve checked out the branch you want to merge to master. For example, if I’m in the master branch of a repo and someone has opened a pull request for a branch called feature-x, I could merge it from the command-line like so: git merge-pr feature-x.

Now, go forth and merge with glee, in safety, and without leaving our beloved shell. ❤

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

Topics:
github

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}