Git Tag Concept and Release Management

We create tags to track our releases. After a release, our code may be updated. In that case, if we want to see what exactly was in a particular release, we can just go to that release tag.

Create a tag:

Without a message (lightweight tag):

git tag <tag-name>
Ex: git tag v1.0.0

With a message (Annotated Tags):

a. git tag  -a  <tag-name> 

Note: it will open a git tag message editor. Write your message and exit.
To write in the tag message editor enter i
To get exit from the editor: 1. Esc -> :wq (Save and exit)
2. Esc -> :q! (exit without saving)

 b. git tag <tag-name>  -a -m "message" 

Note: Git will tag the commit and annotate it with the provided message

Annotated tags are recommended because they include extra information such as:

> The person who made the tag
> The date on which the tag was made
> The message for the tag

View a tag message

git tag -l --format='%(contents)' <tag name>

push a tag:

git push origin <tag-name>

*if you want to push all tags then use the below command: git push –tags

List/view all tags:

git tag     or
git tag --list

Fetching all the remote tags and working on a Specific tag:

git fetch <remote>

Then check for the available tags:

git tag -l

Then switch to that specific tag using the below command:

git checkout <tag-name>

Delete a tag:

Delete a local tag:

git tag -d <tag-name>

add regexp to match tags to delete

git remove-tags <regexp>
Ex: git tag 'v1.0.0' -a -m "message"
    git remove-tags 'v10.0.*'

This will delete all the tags started with v10.0.

Delete a remote tag:

 git push --delete origin <tag-name>

See code examples in our GitHub repository.

Follow us on social media

Author