- 
      
 - 
        
Save isunil/a0b1ac1ac1263a759fe6078f7a1da0c1 to your computer and use it in GitHub Desktop.  
    Bash script to automate the Git Flow tag/release process
  
        
  
    
      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
    
  
  
    
  | #This script is modified from below source to match to our GitFlow | |
| #Help Ref: https://gist.github.com/bclinkinbeard/1331790 | |
| #Please change this script according to your team needs | |
| #This script won't handle any errors and empty inputs | |
| #!/bin/bash | |
| { | |
| read -r -p "Select your Repository(c:/git/repo-name): Select 1-Repo1, 2-Repo2, 3-Repo3: " input | |
| case "$input" in | |
| [1]) | |
| cd ~ | |
| cd /C/Git/Repo1 | |
| echo 'repo switched to Repo1..' | |
| ;; | |
| [2]) | |
| cd ~ | |
| cd /C/Git/Repo2 | |
| echo 'repo switched to Repo2..' | |
| ;; | |
| [3]) | |
| cd ~ | |
| cd /C/Git/Repo3 | |
| echo 'repo switched to Repo3..' | |
| ;; | |
| *) | |
| cd ~ | |
| echo 'no repo selected..' | |
| ;; | |
| esac | |
| #git fetch | |
| git checkout develop | |
| #git pull | |
| git pull | |
| # current Git branch | |
| branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
| # Year.Month.Day 18.01.01, 17.02.12, etc. | |
| year=$(date +%y) | |
| month=$(date +%m) | |
| read -r -p "Select your release number - $year.$month.DD: " day | |
| versionLabel=$year.$month.$day | |
| # establish branch and tag name variables | |
| devBranch=develop | |
| masterBranch=master | |
| releaseBranch=release/$versionLabel | |
| echo $releaseBranch'_created' | |
| # create the release branch from the -develop branch | |
| git checkout -b $releaseBranch $devBranch | |
| echo 'release branch' $releaseBranch 'created' | |
| # merge release branch with the new version number into master | |
| #git checkout $masterBranch | |
| #git merge --no-ff $releaseBranch | |
| # create tag for new version from -master | |
| git tag $releaseBranch'_created' | |
| read -r -p "Are you ready to push new Branch/Tag? [y/N] - Reset - R- Removes all local changes " response | |
| case "$response" in | |
| [yY][eE][sS]|[yY]) | |
| git push origin $releaseBranch | |
| git push origin tag $releaseBranch'_created' | |
| echo 'changes commited to remote' | |
| ;; | |
| [nN][oO]|[nN]) | |
| echo 'changes not commited to remote' | |
| ;; | |
| *) | |
| # remove release branch | |
| git checkout develop | |
| git branch -d $releaseBranch | |
| git tag -d $releaseBranch'_created' | |
| echo 'all local changes reverted..' | |
| ;; | |
| esac | |
| } || { # catch | |
| # save log for exception | |
| echo 'something went wrong..' | |
| echo 'please check your repository paths and connections..' | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment