Skip to content

Instantly share code, notes, and snippets.

@andypa
Forked from bclinkinbeard/release.sh
Last active September 5, 2019 14:12
Show Gist options
  • Save andypa/e24bb4555688715bc59d917b1eb65668 to your computer and use it in GitHub Desktop.
Save andypa/e24bb4555688715bc59d917b1eb65668 to your computer and use it in GitHub Desktop.
Bash script to automate the Git Flow tag/release process
#!/bin/bash
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# latest version
latestVersion=$(git describe --tags `git rev-list --tags --max-count=1`)
# bump version
bumpVersion=$1
a=( ${latestVersion//./ } )
case $bumpVersion in
major)
((a[0]++))
a[1]=0
a[2]=0
;;
minor)
((a[1]++))
a[2]=0
;;
patch)
((a[2]++))
;;
*)
echo "Usage: release.sh major|minor|patch"
exit 1;
esac
versionLabel="${a[0]}.${a[1]}.${a[2]}"
# establish branch and tag name variables
devBranch=develop
masterBranch=master
releaseBranch=release-$versionLabel
# create the release branch from the -develop branch
git checkout -b $releaseBranch $devBranch
# commit version number increment
git commit -am "Incrementing version number to $versionLabel"
# 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 $versionLabel
git push origin
# merge release branch with the new version number back into develop
git checkout $devBranch
git merge --no-ff $releaseBranch
# remove release branch
git branch -d $releaseBranch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment