How to Create Annotated Tag in Git: Simple Guide
To create an annotated tag in Git, use the command
git tag -a <tagname> -m "<message>". This creates a tag with a message and stores extra metadata like the tagger's name and date.Syntax
The command to create an annotated tag in Git has three parts:
git tag: The base command to create tags.-a <tagname>: The -a option means 'annotated' and<tagname>is the name you give your tag.-m "<message>": The -m option adds a message describing the tag.
bash
git tag -a <tagname> -m "<message>"Example
This example creates an annotated tag named v1.0 with a message describing the release.
bash
git tag -a v1.0 -m "First stable release"
Output
git show v1.0
commit 9fceb02...
Tagger: Your Name <you@example.com>
Date: Fri Apr 23 14:00 2024 +0000
First stable release
commit message and changes...
Common Pitfalls
Common mistakes when creating annotated tags include:
- Forgetting the
-moption, which causes Git to open an editor for the message instead of using a quick inline message. - Using lightweight tags (
git tag <tagname>) instead of annotated tags, which lack metadata. - Not pushing tags to the remote repository after creation.
To push tags, use git push origin <tagname>.
bash
git tag v1.0 # This creates a lightweight tag without message or metadata git tag -a v1.0 -m "Release version 1.0" # Correct annotated tag with message
Quick Reference
| Command | Description |
|---|---|
| git tag -a | Create an annotated tag with a message |
| git tag | Create a lightweight tag without metadata |
| git show | View details of a tag |
| git push origin | Push a tag to remote repository |
Key Takeaways
Use
git tag -a <tagname> -m "<message>" to create annotated tags with metadata.Annotated tags store the tagger's name, date, and a message for better tracking.
Lightweight tags lack metadata and are created without the
-a option.Remember to push tags to the remote repository using
git push origin <tagname>.If you omit
-m, Git opens an editor to enter the tag message.