Skip to content

Instantly share code, notes, and snippets.

@rixth
Created March 1, 2013 21:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rixth/5068163 to your computer and use it in GitHub Desktop.
Save rixth/5068163 to your computer and use it in GitHub Desktop.
Usage: git-integrate base-branch <branches-to-merge>*
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