Created
March 24, 2015 15:27
-
-
Save wesleybliss/21bf713d1ca5d2ceacd2 to your computer and use it in GitHub Desktop.
Git merge all branches matching a pattern.
This file contains hidden or 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
#!/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