Over a million developers have joined DZone.

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

The DevOps Zone is brought to you in partnership with Sonatype Nexus. The Nexus Suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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. ❤

The DevOps Zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:
github

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}