Command
git tagExplanation
The `git tag` command is used to create, list, and manage tags in a Git repository. Tags are references that point to specific commits, often used to mark release versions (like `v1.0` or `v2.1.3`). There are two main types of tags: **lightweight** and **annotated**. Lightweight tags are simple pointers to a commit, while annotated tags are stored as full objects in the Git database and include additional metadata such as the tagger’s name, email, date, and a message. Annotated tags are generally preferred for public releases because they include more context. You can also use tags to roll back to a specific version, compare changes between releases, or sign tags cryptographically for verification.
Common Use Cases
- •Marking release versions in a project (e.g., v1.0, v2.0)
- •Referencing specific commits easily by name
- •Creating signed tags for verified releases
- •Organizing repository milestones
Best Practices
- ✓Use annotated tags for releases (`git tag -a v1.0 -m "Release message"`) for better tracking
- ✓Always push tags after creation using `git push origin <tag>` or `git push --tags`
- ✓Use semantic versioning (e.g., v1.0.0) for clarity
- ✓Sign important release tags for authenticity and security
Common Mistakes to Avoid
- ⚠Creating lightweight tags when annotated tags are preferred for releases
- ⚠Forgetting to push tags to remote after creation
- ⚠Reusing tag names, causing confusion or overwriting old tags
- ⚠Not signing important release tags
Troubleshooting
Problem: Tag not visible on remote repository
Solution: Tags are not pushed automatically with commits. Use `git push --tags` to upload all tags or `git push origin <tag-name>` for a specific tag.
Problem: Accidentally created wrong tag name
Solution: Delete the incorrect tag locally using `git tag -d <tag-name>` and recreate it with the correct name.
Problem: Need to tag a previous commit
Solution: Specify the commit hash when creating the tag, e.g., `git tag -a v1.0 <commit-hash>`.
Examples
List all tags in the repository
git tagCreate a lightweight tag named v1.0
git tag v1.0Create an annotated tag with a message
git tag -a v1.0 -m "Release version 1.0"Display details about a specific tag
git show v1.0Create a signed annotated tag (requires GPG)
git tag -s v1.0 -m "Signed release tag"More
Manage Worktrees
Manage multiple working trees linked to a single Git repository for simultaneous development across branches
Initialize Repository
Create an empty Git repository in a directory to start version controlling your project
Clone Repository
Clone an existing Git repository from a remote server to your local machine, creating a complete copy with full history