Git Tutorial
- 1. Introduction to Git & VCS
- 2. Installation & Configuration
- 3. Git Architecture & Concepts
- 4. Basic Workflow (add/commit)
- 5. Git Log & History
- 6. Branching Basics
- 7. Merging & Conflict Resolution
- 8. Git Rebasing
- 9. Undoing Changes
- 10. Working with Remotes
- 11. Git Stashing
- 12. Git Tagging
- 13. Git Ignore & Attributes
- 14. Advanced Git Tools
- 15. Best Practices & Workflows
12. Git Tagging
Like most version control systems, Git has the ability to tag specific points in a repository's history as being important. Typically, this functionality is used to mark **Release Points** (e.g., v1.0.0, v2.4.0-beta) in your production cycle.
Types of Tags
Git supports two main types of tags: Lightweight Tags and Annotated Tags.
| Tag Type | Description | Key Features |
|---|---|---|
| Lightweight Tag | Basically a pointer that doesn't change; just a reference to a specific commit. | Extremely simple, created quickly, stores no additional metadata. |
| Annotated Tag | Stored as full objects in the Git database. Recommended for official software releases. | Contains checksum hash, tagger name, email, date, and a specific tagging message. Can be signed and verified with GPG keys. |
Tagging Commands
1. Creating an Annotated Tag (Recommended)
To create an annotated tag at your current commit point, run the tag command with -a (annotate) and -m (message):
git tag -a v1.0.0 -m "First official production release version 1.0.0"2. Creating a Lightweight Tag
To create a simple lightweight tag without a message or extra metadata:
git tag v1.0.0-lightweight3. Listing Your Tags
To view all tags in your repository in alphabetical order:
git tagYou can search for tags matching a specific wild-card pattern, for example, to see only the v1.x releases:
git tag -l "v1.*"4. Viewing Tag Details
To see the tagger information, date, message, and the exact commit details associated with a tag, use:
git show v1.0.05. Tagging Past Commits
You don't have to tag immediately when making a commit. If you forgot to tag a release from yesterday, simply look up its commit hash in git log and add the hash at the end of the tag command:
# Tag a specific past commit
git tag -a v0.9.0 a8f1b2c -m "Retroactive tag for release 0.9.0"Working with Remote Tags
By default, git push **does not upload tags** to remote hosting servers. You must explicitly push tags to your remote repository:
# Push a specific tag to remote origin
git push origin v1.0.0
# Push ALL local tags that aren't already on the remote server
git push origin --tagsDeleting Tags
If you made a mistake and want to delete a tag on your local machine:
git tag -d v1.0.0To remove the tag from your remote server, run:
git push origin --delete v1.0.0