Created
June 13, 2016 09:27
-
-
Save OliverJAsh/088ae37ce842e34971e6ecef8d6b7dc6 to your computer and use it in GitHub Desktop.
git apply-pr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#compdef git-apply-pr | |
_git-apply-pr() { | |
_git-branch | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Applies the PR for a given branch via rebase, and delete branches (local and | |
# remote) afterwards. | |
# Defaults to current branch. | |
# | |
# Usage: git apply-pr [<branch-name>] | |
# | |
# Installation: ln -s git-apply-pr /usr/local/bin | |
set -exu pipefail | |
BRANCH=`git rev-parse --abbrev-ref HEAD` | |
HEAD=${1:-$BRANCH} | |
BASE=${2:-master} | |
TMP="tmp" | |
git log --oneline $BASE..$HEAD | |
echo | |
read -p "Rebase $HEAD into $BASE?" | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo | |
git checkout $BASE \ | |
&& git pull \ | |
&& echo "Rebase" \ | |
&& git checkout -b $TMP $HEAD \ | |
&& git rebase $BASE \ | |
&& git checkout $BASE \ | |
&& git merge --ff-only $TMP \ | |
&& echo "Delete branches" \ | |
&& git branch -d $TMP \ | |
&& git branch -D $HEAD \ | |
&& git push origin :$HEAD \ | |
&& git push | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment