Git Tag Explained — Creating and Pushing Tags
So far, we’ve seen how to create and delete branches in Git.
Now let’s move to another important concept: Git tags.
Tags are used to mark important points in your project’s history, like releases or milestones.
Think of them as bookmarks in a book — when you want to quickly come back to a specific point, you place a tag there.
Why Use Git Tags?
Imagine you are working on a project:
- At first, you release the MVP (Minimum Viable Product) — a basic version of your app.
- Later, you add a subscribe feature for users.
- Then you add email notifications.
At each important stage, you want to mark the commit so that you can always come back to it.
👉 That’s where Git tags help.
Creating a Tag
You can create a lightweight tag on the current commit:
git tag v0.1
👉 This attaches a tag named v0.1 to the current commit.
Check commits with tags:
git log --oneline
Output:
a1b2c3d (HEAD -> main, tag: v0.1) Added product.txt
f9e8d7c Initial commit
✅ The commit now shows the v0.1 tag.
Visual Representation
The tag v0.1 is pointing to commit 2.
Pushing Tags to GitHub
By default, when you push, tags are not pushed automatically.
Push a single tag:
git push origin v0.1
Push all tags:
git push origin --tags
👉 After pushing, you’ll see the tags under the Releases section in GitHub.
Listing All Tags
To see all the tags in your repository:
git tag
👉 Output:
v0.1
v1.1
v1.2
Types of Tags in Git
Git supports two types of tags:
-
Lightweight Tag
- A simple pointer to a commit.
- Created with
git tag v0.1. - Like a quick bookmark.
-
Annotated Tag
- Stores extra information like author, date, and a tagging message.
- Created with
git tag -a v1.0 -m "Release 1.0". - Recommended for releases.
👉 In this blog, we covered lightweight tags. We’ll dive into annotated tags in the next post.
Summary
- Git tags are like bookmarks for important commits.
- Use
git tag <name>to create a tag. - Push tags with
git push origin <tag>orgit push origin --tags. git taglists all tags in the repo.- Two types of tags: Lightweight and Annotated.
Keep Learning 🚀
👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.
👉 My YouTube Channel – More videos, more fun, and lots of learning!
👉 📺 Watch this topic in video form
Stay curious, keep coding, and let’s make learning fun together! 🎉