git tags are names of stable code that point to specific commits in the history of commits in a repository.
For example, you are adding several features with multiple releases, Each release is a stable code that represents a tag. It helps to revert the code’s previous version in case any failure happens. Each release follows semantic release version numbers. So tag represents semantic release version numbers. example v1.0.1, v2.4.1 so on.
Tags are an aliases to commit hashes.
Create a tag
There are two types of tags
- Annotated tag: These tags contain more additional data such as name, message and email, date of a tag
git tag -a tagname -m "commit message"
- Simple tag: Simple reference and point reference in the history of the repository.
git tag tagname
To create a tag with a specific commit hash
git tag tagname commithash
View all tags
git tag command shows all tags of a remote repository
git tag
Delete git tag
To delete a tag, pass -d
option to the git tag option along with the tag name.
git tag -d tagname
This deletes a local tag from a local repository.
To remove the remote tag from a repository
git push origin :tagname
or
git push --delete origin tagname
Checkout and push tag
git checkout tagname
It checkout tag into the local repository, You can make changes and push the changes to remote using the below command.
git push origin --tags
Rename tag
To rename a tag, please follow the steps
First, rename the tag to a new name using the below command
git tag newtagname oldtagname
Next, Delete an old tag name using the below command
git tag -d oldtagname
The above two commands make changes in the local tag repository
To push the changes, means renaming to new tag name
git push origin newtagname :oldtagname
This pushes a new tag name and deletes the old tag name from a remote repository.