Skip to content

Instantly share code, notes, and snippets.

@neight-allen
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neight-allen/97bc39fd0cafd9ed7e61 to your computer and use it in GitHub Desktop.
Save neight-allen/97bc39fd0cafd9ed7e61 to your computer and use it in GitHub Desktop.
I use this to tag commits when I'm ready to deploy to production. I made this so I don't have to remember what the last version was, and so I don't have to type the command either. To use as a git command (git nexttag) save it as git-nexttag somewhere on the path, like /usr/local/bin.
#!/bin/bash
lasttag=$(git describe --abbrev=0 --tags)
tagparts=(${lasttag//./ })
if [ ! -z $1 ] && [ $1 == "--hotfix" ]
then
declare -i hotfix
hotfix=1
if [ ${tagparts[2]} ]
then
hotfix=${tagparts[2]}+1
fi
newVersion=${tagparts[0]}.${tagparts[1]}.$hotfix
message="Version 1.$stringMinorVersion Hotfix #$hotfix"
else
declare -i newMinorVersion
newMinorVersion=${tagparts[1]}+1
stringMinorVersion="$(printf "%02d" $newMinorVersion)"
newVersion=${tagparts[0]}.$stringMinorVersion
message="Version 1.$stringMinorVersion"
fi
git tag -a $newVersion -m "$message"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment