Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
# Do an octopus merge and select a strategy for each branch you
# want to merge.
STRATEGY="recursive"
HEADS=( $(git rev-parse HEAD) )
git checkout HEAD^{}
while [ $# -gt 0 ]; do
if [ "$1" = "-s" ]; then
shift; STRATEGY="$1"
else
printf "Merging $1 with $STRATEGY strategy... "
HEADS[${#HEADS[*]}]=$(git rev-parse $1)
if ! git merge -s $STRATEGY $1 1>/dev/null 2>&1; then
printf "failed\n"; exit 1
fi
printf "\n"
fi
shift
done
n=$(( ${#HEADS[*]} - 1 ))
git reset --soft HEAD~$n
rm -f .git/MERGE_HEAD
for head in ${HEADS[@]}; do
echo $head >> .git/MERGE_HEAD
done
git commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment