#!/bin/bash parent="release/" branchout="master" # if this is the first time the release branch is created it has to be from master after all the ut,it,sc tests/analysis. usage="usage:\n$0 [options]\noptions:\n -d\tdelete the branches only" branches=("master" "staging" "develop") opt_d=0 for arg in $@; do if [[ "-d" == "$arg" ]];then opt_d=1 break fi done # get release name if [[ "$1" == "" ]]; then echo "git release branch is empty" echo -e "$usage" exit 2 fi release="$1" if [[ "$1" == /* ]]; then parent="" release="${release:1}" # remove the begining / fi # get git folder name if [[ "$2" == "" ]]; then echo "git folder is empty" echo -e "$usage" exit 1 fi folder="$PWD/$2" # get release name if [[ "$3" == "" ]]; then echo "branch from is empty" echo "$branchout branch will be used as branch out" else branchout="$3" fi # cd to the git folder and check if exists cd "$folder" if [[ "$?" != 0 ]]; then echo "incorrect git folder" echo -e "$usage" exit 4 fi echo "$PWD" previous=$(git branch --show-current) git checkout "$branchout" if [[ "$?" != 0 ]]; then echo "cannot checkout to $branchout" echo "$usage" exit 5 fi # start creating echo "Follwoing branches will be created:" for branch in ${branches[@]}; do echo " - $parent$release/$branch" done echo message="I Confirm $parent$release on $( basename $folder )" echo $message echo "----------" read -p "continue [ ${message^^} ] (type in lowercase) : " confirm echo if [[ ! ( "$confirm" == "${message,,}" ) ]]; then echo "Aborted ... " exit 0 fi for branch in ${branches[@]}; do echo " ------------------------------------------------------------ " echo " ----- check out to $branchout" git checkout "$branchout" echo " ----- deleting local $parent$release/$branch" git branch -d "$parent$release/$branch" echo " ----- creating local $parent$release/$branch" git checkout -b "$parent$release/$branch" echo " ----- pushing origin $parent$release/$branch" git push origin "$parent$release/$branch" --force done git checkout $previous