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

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.


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.


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


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}