Skip to content

Instantly share code, notes, and snippets.

@dtiemann83
Last active June 12, 2023 13:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dtiemann83/cfa16ade69a3ea451ad760d4118a9351 to your computer and use it in GitHub Desktop.
Save dtiemann83/cfa16ade69a3ea451ad760d4118a9351 to your computer and use it in GitHub Desktop.
A quick BASH script to automatically add a git tag by incrementing --major --minor --bug version, based on (most recent) previous tag.
#!/bin/bash
CURTAG=`git describe --abbrev=0 --tags`;
CURTAG="${CURTAG/v/}"
IFS='.' read -a vers <<< "$CURTAG"
MAJ=${vers[0]}
MIN=${vers[1]}
BUG=${vers[2]}
echo "Current Tag: v$MAJ.$MIN.$BUG"
for cmd in "$@"
do
case $cmd in
"--major")
# $((MAJ+1))
((MAJ+=1))
MIN=0
BUG=0
echo "Incrementing Major Version#"
;;
"--minor")
((MIN+=1))
BUG=0
echo "Incrementing Minor Version#"
;;
"--bug")
((BUG+=1))
echo "Incrementing Bug Version#"
;;
esac
done
NEWTAG="v$MAJ.$MIN.$BUG"
echo "Adding Tag: $NEWTAG";
git tag -a $NEWTAG -m $NEWTAG
@MichaelCurrin
Copy link

Thanks for sharing! I had an idea to do a shell script like this and this saved me a lot of trouble.

Here is my project: https://michaelcurrin.github.io/auto-tag/

I built on the logic to always fetch tags and added a dry run option. I link back to this gist on the About page.

@onovaes
Copy link

onovaes commented Nov 18, 2020

Amigo, obrigado por compartilhar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment