By simply tagging your committed changes in a Git repository you can mark specific point in the repository to stand out from rest of the commits.
Why adding tags?
For various reasons, you may want to mark certain commits important than others. Commonly git tags are used to mark release versions.
View existing tags:
Adding a new tag:
There are two types git tags. Lightweight tags which work as just names and Annotated tags which contains a meaningful message.
Creating a Lightweight tag
git tag <TAG_TEXT>
Example output for adding a lightweight git tag:
git tag v1.0.1
Creating a Annotated tag
git tag -a <TAG_TEXT> -m <TAG_MESSAGE>
Example output for adding an annotated git tag:
git tag -a v1.0.1 -m "version 1.0.1 after beta testing"
View tag details
There are some instances you need to view data associated with a tag. Below command can be used to view information like Author, Date and comments.
git tag show
Example output for git show command:
git show v1.0.1 tag v1.0.1 Tagger: Crypto Memos <[email protected]> Date: Fri Dec 12 18:20:00 2012 -0000
Checking out a repository based on a tag:
Another common use of git tags will be to checkout a git repository based on a tag id.
git checkout <TAG_TEXT>
Pushing a tag to remote:
After tagging the local repository with a new tag, we need to push the newly created tag to remote.
git push origin --tags
Removing an existing git tag:
Last, you may want to delete a git tag you already created.
git tag -d <TAG_TEXT>
Example output for deleting a git tag :
git tag -d v1.0.1 Deleted tag 'v1.0.1' (was e1e7rtd)
Git-scm.com. (2019). Git – Tagging. [online] Available at: https://git-scm.com/book/en/v2/Git-Basics-Tagging [Accessed 1 Jan. 2020].