How to tag a commit in Git
Tagging commits in Git provides a way to mark important milestones like releases, version numbers, and significant checkpoints in your project history.
As the creator of CoreUI, a widely used open-source UI library, I’ve tagged countless releases and versions across multiple CoreUI repositories to track release history and enable easy rollbacks.
From my 25 years of experience in software development and version control, the most effective approach is to use annotated tags with git tag -a for releases and lightweight tags for temporary markers.
This method provides clear version management and release tracking.
Use git tag with the -a flag for annotated tags or without flags for lightweight tags to mark important commits.
# Create an annotated tag (recommended for releases)
git tag -a v1.2.3 -m "Release version 1.2.3"
# Create a lightweight tag
git tag v1.2.3-beta
# Tag a specific commit
git tag -a v1.2.2 -m "Bug fix release" a1b2c3d
# List all tags
git tag
# List tags with pattern matching
git tag -l "v1.*"
# Show tag information
git show v1.2.3
# Push tags to remote
git push origin v1.2.3
# Push all tags
git push origin --tags
Annotated tags created with -a include metadata like tagger name, email, date, and a tagging message, making them ideal for releases. Lightweight tags are simple pointers to specific commits without additional metadata. Use semantic versioning (e.g., v1.2.3) for consistent release numbering. The -m flag adds a tagging message directly, or omit it to open an editor. Tags must be explicitly pushed to remote repositories using git push origin tagname or --tags for all tags.
This is the same tagging strategy we use in CoreUI development for tracking releases and creating stable reference points for version management. Always use annotated tags for public releases as they provide complete metadata and are treated as full objects in Git, making them more suitable for distribution and archival purposes.



