Skip to content

Instantly share code, notes, and snippets.

@mberlanda
Created November 14, 2018 16:41
Show Gist options
  • Save mberlanda/b542e16bc18356c2d3f8d11a48c25b4b to your computer and use it in GitHub Desktop.
Save mberlanda/b542e16bc18356c2d3f8d11a48c25b4b to your computer and use it in GitHub Desktop.
Multiple Git Tagging on the same repo

Git tagging cookbook

Let's suppose that we want to keep two different tag versioning on the same repo:

  • v[0-9]* for master branch versions
  • d[0-9]* for development branch versions

Basic commands: https://git-scm.com/book/en/v2/Git-Basics-Tagging

Please note I am using git version 2.14.1. The behavior may differ according to your version

# Retrieve all tags
git tag
# Describe the latest applicable tag
git describe --tags
# If no tag available you will see something like
# fatal: No names found, cannot describe anything.

# Before creating new tags, make sure you are up to date with origin
git fetch --tags origin

# Create one tag
git tag -a d1 -s -m "first development branch tag"
git push origin d1

# I can look for specific d tags versions
git describe --match "d[0-9]*" --abbrev=0 HEAD --tags
git tag -l -n "d[0-9]*"
# d1              first development branch tag

# Increase tag version
D_TAG=$(git describe --match "d[0-9]*" --abbrev=0 HEAD --tags)
VNUM=${D_TAG//d/}
echo "d$((VNUM + 1))"
# d2

# Remove tag locally and remotely
git tag -d d1
git push --delete origin d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment