Refresh a Latest Git Tag for Current Release

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to delete and recreate a Git tag named latest to a specific release version.


Prerequisites


Pull Current Tags Locally

git pull


List Local Tags

git tag -l


Delete Local Tag/s

git tag -d latest


Push Deletions to Github

git push origin :refs/tags/latest


Checkout Release to tag as latest

In this example we'll be using the tag 1.0.0 as the version to tag as latest.

git checkout 1.0.0


Create latest Tag Locally

Create latest tag at this head version locally

git tag -af latest -m "1.0.0 Release"


Push Tags to Remote (Github)

git push origin --tags


Example BASH Script

Here's and example BASH script that could be used for automation.

#!/usr/bin/env bash

function usage () {
usagemessage="
usage: $0 -t [tagname]

-t Tag Name to Set as latest     :  (Required)
"
    echo "$usagemessage";
}

# Argument Parser
while getopts "t:" opts; do
    case $opts in
        t ) tag=$OPTARG;;
    esac
done

# Bail if Missing Tag Name
if [ -z $tag ]; then
    usage
    echo "ERROR: Release Tag Name Missing!"
    exit 1
fi

git pull
git tag -d latest
git push origin :refs/tags/latest
git checkout ${tag}
git tag -af latest -m "${tag} Release"
git push origin --tags
git checkout master


Related Articles


Sources