Why use Git tag?
Git tags are like milestones, markers or a specific point in the repo’s history marked as significant. Tags are usually used to mark stable releases or achievement of very important milestones.
Tags can help the users of the repo to easily navigate to the important parts of the code history like release points. For example, on Github, you can easily grab archive of “tags” in the current repo.
Dealing with Tags
List tags:
1 |
git tag |
Search in tags:
1 |
git tag -l v1.* |
That will display tags starting with “v1.” – use regex and your common sense to do complex queries. This can help you narrow down your query in case you have plenty of tags in the repo.
View a tag:
1 |
git show v1.4 |
Note: The command doesn’t have “tag” in it. 🙂
Adding tags:
1 |
git tag -a v1.0.0 -m 'version 1' |
The “-a” denotes an annotated tag – means it’s stored as a full object in the git database where as a non annotated tag is just a pointer to a specific commit. Just drop the “-a” to create normal tags. The “-m” option is of course obvious, it allows you to add a message to the annotated tag.
Adding Tags later:
1 |
git tag -a v1.2 9fceb02 |
This will add the “v1.2” tag to the commit marked by “9fceb02”. “git log” will help you get the checksum of the commit.
Pushing Tags to remote branch:
1 |
git push --tags |
PS: Git tags are not pushed automatically with generic “git push” command. You must push the tags separately.
Deleting a tag:
1 |
git tag -d v1.0.0 |
That will delete the tag v1.0.0.
These are the very common uses of Git tags. Look at the git manual for more complex stuff you can do with tagging 🙂
3 replies on “Tagging in Git: Why? How?”
nice one masnun vai. simple and optimistic
thanks 🙂
Nicely explained, thanks!