← Back to Chapters

Git Tagging

?️ Git Tagging

? Quick Overview

Git Tagging is used to mark specific points in a repository’s history as important. Tags are commonly used for releases such as v1.0 or milestones. Unlike branches, tags are fixed references and do not move.

? Key Concepts

  • Tags point to specific commits
  • Used mainly for versioning and releases
  • Tags are immutable by default
  • Two types: lightweight and annotated

? What is a Git Tag?

A Git tag is a reference to a specific commit, often used to mark a particular point in a repository’s history such as a release version. Tags act like snapshots and are typically used for versioning code.

? Syntax / Theory

Tags can be created in two main forms:

  • Lightweight Tag – Just a pointer to a commit
  • Annotated Tag – Stores metadata like author, date, and message

? Code Examples

? View Code Example
// Create a lightweight tag on the current commit
git tag v1.0
? View Code Example
// Create an annotated tag with a message
git tag -a v1.1 -m "First stable release"
? View Code Example
// List all tags in the repository
git tag
? View Code Example
// Show commit details associated with a tag
git show v1.0

? Pushing & Deleting Tags

? View Code Example
// Push a specific tag to remote repository
git push origin v1.0
? View Code Example
// Push all local tags to remote
git push --tags
? View Code Example
// Delete a tag locally
git tag -d v1.0
? View Code Example
// Delete a tag from remote repository
git push --delete origin v1.0

? Live Output / Explanation

What Happens?

After tagging a commit, Git stores a permanent reference to that commit hash. When you push tags, collaborators can check out exactly the same version of code.

? Interactive Visual (Conceptual Diagram)

Commit A Commit B Commit C ?️ v1.0

? Use Cases

  • Marking release versions
  • Creating deployment checkpoints
  • Referencing stable builds
  • Rollback to known-good versions

? Tips & Best Practices

  • Prefer annotated tags for releases
  • Follow consistent naming like v1.0.0
  • Always push tags explicitly

? Try It Yourself

  • Create an annotated tag for your latest commit
  • Push the tag to a remote repository
  • Inspect the tag using git show
  • Delete a tag locally and remotely