Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created June 12, 2015 12:57
Show Gist options
  • Save OliverJAsh/db09fea37fa0613737b6 to your computer and use it in GitHub Desktop.
Save OliverJAsh/db09fea37fa0613737b6 to your computer and use it in GitHub Desktop.
git merge-pr
#!/bin/bash
# Usage: git merge-pr [<branch-name>]
# ln -s ~/Desktop/git-merge-pr /usr/local/bin
#
# Merge the PR for a given branch, and delete branches (local and remote)
# afterwards.
# Defaults to current branch.
set -e
BRANCH=`git rev-parse --abbrev-ref HEAD`
HEAD=${1:-$BRANCH}
BASE=${2:-master}
git log --oneline $BASE..$HEAD
echo
read -p "Merge $HEAD into $BASE?"
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
git checkout $BASE \
&& git pull \
&& echo "Merge" \
&& git merge --no-edit $HEAD \
&& git push \
&& echo "Delete branches" \
&& git branch -d $HEAD \
&& git push origin :$HEAD
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment