Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Last active June 27, 2018 12:32
Show Gist options
  • Save OliverJAsh/298e2f2ba05a7c89e32822667c70b08c to your computer and use it in GitHub Desktop.
Save OliverJAsh/298e2f2ba05a7c89e32822667c70b08c to your computer and use it in GitHub Desktop.
git pr-merge-and-clean
#!/bin/bash
# Dependencies:
# - hub (`brew install hub`)
# - climergebutton (`brew install vitorgalvao/tiny-scripts/climergebutton`)
set -eou pipefail
# TODO:
# - fail if no URL argument
# - fail if no PR found
# - move token to config/argument
URL=$1
TOKEN="CHANGEME"
HEAD_BRANCH=$(hub pr list -f "%U %H%n" | grep $URL | cut -d ' ' -f 2)
BASE_BRANCH=$(hub pr list -f "%U %B%n" | grep $URL | cut -d ' ' -f 2)
echo "Merging $URL"
climergebutton --merge-method merge --token $TOKEN $URL
echo "Updating local base branch ($BASE_BRANCH)"
git checkout $BASE_BRANCH
git pull --rebase
echo "Deleting local and remote head branches ($HEAD_BRANCH)"
# Don't fail if remote fails
set +e
git push origin :$HEAD_BRANCH
set -e
git branch --delete --force $HEAD_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment