Created
March 1, 2013 21:55
-
-
Save rixth/5068163 to your computer and use it in GitHub Desktop.
Usage: git-integrate base-branch <branches-to-merge>*
This file contains 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
function git-integrate () { | |
integration_branch="integration_$RANDOM" | |
base_branch=$1 | |
delete_integration_branch () { | |
echo "Checking back out to $base_branch" | |
git checkout $base_branch | |
echo "Deleting integration branch $integration_branch" | |
git branch -D $integration_branch | |
} | |
reset_the_things () { | |
reply= | |
vared -p "Do you want to reset? " reply | |
if [[ $reply =~ ^[Yy]$ ]] | |
then | |
echo "Resetting to head hard" | |
elif git reset --hard HEAD | |
then | |
delete_integration_branch | |
fi | |
} | |
echo "Switching to base branch: $base_branch" | |
git checkout $base_branch || { | |
return 1 | |
} | |
echo "Creating integration branch: $integration_branch" | |
git checkout -b $integration_branch || { | |
return 1 | |
} | |
for branch in "$@" | |
do | |
if [ "$branch" != "$base_branch" ] | |
then | |
echo "Attempting to merge $branch" | |
git merge --no-edit $branch || reset_the_things | |
fi | |
done | |
remove= | |
vared -p "Integration succeeded. Remove $integration_branch? " remove | |
if [[ $remove =~ ^[Yy]$ ]] | |
then | |
delete_integration_branch | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment