Tagging in Git

Tagging in Git

Tags are used to mark your code, likely branch names but the user can’t checkout tags. tags are just like versions of your code like v1,v2, v2.2, Creating a tag requires one parameter: the name of the tag

List all tags

git tag

Tag the latest commit

git tag v1.0 or git tag <tag name>

Create a tag called beta from the next to last commit

git tag <tag name> HEAD^

Delete your tag

git tag -d
caution

Tags cannot begin or end with /.

caution

You cannot use the characters ^, *, or: inside tags

There are two types of tags

  • Annotated tags
  • Lightweight tags

Annotated tags

annotated tags are useful when you release project publicly, annotated tags contain metadata kike tag message, timestamp, authour name, release notes etc, these are useful for releasing your project publicly because visitors or other unknown user are able to know the actual details and time stamp of the tag, annotated tags always point to a tag object in the git object database

Command to create annotated tag
git tag -a <tag name>

the above command creates a LOCAL tag on the current branch,but when you push your latest commit to the remote repository, git doesn’t push tags user needs to push tags separately by command

Annotated tag example
git tag -a v2.1.6 -m "NEW feature is released in this tag."

In the above code -m is used to provide a message to the tag, if the user doesn’t use -m, git automatically opens the editor so user can type message

Lightweight Tags

lightweight tags are simple tags which will be used locally mostly, to create lightweight tags just don’t provide any additional parameters like -m,-a .lightweight tag is just a named pointer to the commit

Command to create lightweight tags
git tag <tag name>

Command to push tags

git push origin --tags
Last updated on by vishal devxo