Skip to content

Instantly share code, notes, and snippets.

@Drarok
Forked from sampart/pr-merged.sh
Last active January 4, 2016 09:29
Show Gist options
  • Save Drarok/8602419 to your computer and use it in GitHub Desktop.
Save Drarok/8602419 to your computer and use it in GitHub Desktop.
#!/bin/bash
# PR been merged on github? This will checkout $1 || develop, git pull, and then delete the branch you were on.
# Thanks http://stackoverflow.com/a/1593487/328817
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || branch_name="(unnamed branch)"; # detached HEAD
branch_name=${branch_name##refs/heads/};
if [ "$branch_name" = "develop" ] || [ "$branch_name" = "master" ]
then
echo "Only for feature branches!";
exit 1;
fi
target_branch="$1"
if [ -z "$target_branch" ]
then
target_branch="develop";
fi
git checkout $target_branch
if [ "$?" != "0" ]
then
exit 1;
fi
git pull
git branch -d $branch_name
if [ "$?" != "0" ]
then
exit 1;
fi
echo
echo 'Remaining branches:'
git branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment