Skip to content

Instantly share code, notes, and snippets.

@stilist
Last active February 10, 2022 18:42
Show Gist options
  • Save stilist/544fa961f22144b6803ac3bbc510cd89 to your computer and use it in GitHub Desktop.
Save stilist/544fa961f22144b6803ac3bbc510cd89 to your computer and use it in GitHub Desktop.
Script for creating a branch that combines multiple other branches
#!/usr/bin/env bash
set -euo pipefail
destination_branch_name="${1:-merge-pile}"
branch_list="${2:-branch-list.txt}"
if [[ ! -f "${branch_list}" ]] ; then
echo "ERROR: Branch list file (${branch_list}) doesn't exist" >&2
exit 1
fi
# @see https://stackoverflow.com/a/30781568
if git merge HEAD &> /dev/null ; then
git checkout master
git fetch origin master
git pull origin master \
--ff
# recreate branch from master
git branch \
--delete \
--force \
"${destination_branch_name}" \
&>/dev/null \
|| true
git checkout \
-B \
"${destination_branch_name}" \
origin/master
git checkout \
"${destination_branch_name}"
else
git merge \
--continue
fi
while IFS= read -r branch ; do
git merge \
--ff \
"${branch}"
done < "${branch_list}"
git branch \
--unset-upstream \
|| true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment