Last active
March 19, 2018 14:36
-
-
Save alex-pex/27905c43a244fefcf8d04eae5bbd6d10 to your computer and use it in GitHub Desktop.
Script to create pull-requests when a new version is released https://hub.github.com/
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/env bash | |
hub --version || exit 1 | |
echo | |
git stash -k | |
git pull || exit | |
REF=`git rev-parse --abbrev-ref HEAD` | |
HEAD=`git rev-parse HEAD` | |
HEAD_SHORT=`git rev-parse --short HEAD` | |
echo "$REF HEAD: $HEAD" | |
MERGE_BASE=`git merge-base $HEAD origin/develop~1` | |
echo "$REF MERGE_BASE: $MERGE_BASE" | |
BRANCHES=`git branch -r --contains $MERGE_BASE --no-contains $HEAD --format %\(refname\) | sed -e "s/^refs\/remotes\/origin\///g" | grep "^release/\|^develop"` | |
BRANCHES_INLINE=`echo $BRANCHES | sed "s/ /, /g"` | |
echo | |
echo "Trying to merge $REF into [$BRANCHES_INLINE] branches" | |
for BRANCH in $BRANCHES | |
do | |
echo | |
echo "=== Merging $REF into $BRANCH ===" | |
git checkout --quiet "origin/$BRANCH" | |
git merge --quiet --no-ff --no-commit $REF | |
git diff --cached --quiet && echo "No diff, skip merging" && continue | |
git reset --hard | |
MERGE_NAME=`echo "$HEAD_SHORT/into/$BRANCH" | sed -e "s/\//-/g"` | |
git checkout -b "merge/$MERGE_NAME" | |
if (git merge --quiet --no-ff $REF) | |
then | |
git push -u origin "merge/$MERGE_NAME" | |
else | |
git merge --abort | |
git reset --hard $REF | |
git push -u origin "merge/$MERGE_NAME" | |
fi | |
#hub pull-request -m "Merge $REF into $BRANCH" -b $BRANCH -l "patch/release-merge" | |
hub pull-request -m "Merge $REF into $BRANCH" -b $BRANCH | |
done | |
echo | |
git checkout $REF | |
echo Done! |
You have to edit ~/.gitconfig and enable "ours" merge strategy
[merge "ours"]
driver = true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is useful if you use multiple release branches on a gitflow.
If you have
And you want to publish a v1.1.1
It will create 2 pull requests