Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created March 24, 2015 15:27
Show Gist options
  • Save wesleybliss/21bf713d1ca5d2ceacd2 to your computer and use it in GitHub Desktop.
Save wesleybliss/21bf713d1ca5d2ceacd2 to your computer and use it in GitHub Desktop.
Git merge all branches matching a pattern.
#!/bin/bash
echo
if [ -z "$1" ]; then
echo "Merge all branches matching a pattern (e.g. sprint number) into the current branch."
echo
echo "USAGE"
echo "$0 <pattern>"
exit 1
fi
currentbranch=$(git rev-parse --abbrev-ref HEAD)
branches=$(git branch | grep "$1" | grep -v "$currentbranch" | cut -d' ' -f2-)
echo "The following branches will be merged:"
echo
for b in $branches; do
echo " > $b"
done
echo
response="y"
read -r -p "Continue with merge? (Y/n)" response
if [[ $response =~ ^([nN][oO]|[nN])$ ]]; then
exit 0
fi
for b in $branches; do
git merge $b
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment