In this lesson, you will learn how to use Git tags to permanently bookmark critical points in your project’s history, such as stable releases or major production milestones.
In a collaborative environment, commit hashes are often long and difficult to remember. While branches are designed to move and evolve, tags are designed to remain static, providing a clear "snapshot" of your code exactly as it existed at a specific moment.
Lightweight vs. Annotated Tags
Git offers two primary ways to mark these milestones:
- Lightweight tags: These act as a simple pointer to a specific commit. You can create one using
git tag <tag-name>. Think of this as a bookmark that doesn't carry extra metadata. - Annotated tags: These are stored as full objects in the Git database. They contain the tagger's name, email, date, and a message—much like a commit message. These are highly recommended for public releases, as they provide a permanent record. Create one using the
-aflag:
# Create an annotated tag for a version release
git tag -a v1.0.0 -m "Release version 1.0.0: Initial stable production build"
Working with Tags
Once you have tagged a commit, you can view your list of milestones by running git tag. If you want to see the specific details of a particular tag, use git show v1.0.0.
Importantly, Git does not automatically push tags to your remote repository when you run git push. To share your milestone with your team, you must explicitly push the tag:
# Push a specific tag to the remote
git push origin v1.0.0
# Or, push all local tags at once
git push origin --tags
By marking milestones, you help your team distinguish between "work-in-progress" code on a branch and verified, stable versions of your application. This makes it trivial for collaborators to check out a specific release or reference a known-good state during debugging.
Key Takeaway: Use annotated tags to create descriptive, permanent markers for stable project releases, ensuring they are explicitly pushed to your remote repository so your entire team can access them.