Marking Release Points and Version Management¶
Master the art of tagging commits and managing project versions with Git.
Understanding Tags¶
What Are Git Tags?¶
Git tags are references that point to specific points in Git history. They're typically used to mark release points (v1.0, v2.0, etc.) providing a way to identify important milestones in your project timeline.
gitGraph
commit
commit
commit
commit
commit
commit id: "v1.0" tag: "v1.0"
commit
commit id: "v1.1" tag: "v1.1"
commit
commit id: "v2.0" tag: "v2.0"
commit
Unlike branches, tags don't change position as new commits are added; they remain permanently attached to the same commit unless manually moved.
Types of Tags¶
Git supports two types of tags:
- Lightweight Tags: Simple pointers to commits (like bookmarks)
- Annotated Tags: Full objects stored in Git database with metadata, including tagger name, email, date, and a tagging message
Tags vs. Branches¶
Understanding when to use tags versus branches:
| Tags | Branches |
|---|---|
| Mark specific points in history | Track ongoing development |
| Don't move automatically | Move with new commits |
| Typically used for releases | Used for features, fixes, etc. |
| Are meant to be permanent | Can be temporary and merged |
| Are often used for versioning | Can be deleted or modified |
Creating Tags¶
Lightweight Tags¶
Create simple reference markers:
Create a lightweight tag¶
Create a lightweight tag at a specific commit¶
Annotated Tags¶
Create full tag objects with additional metadata:
Create an annotated tag¶
Create an annotated tag and open editor for message¶
Tagging Previous Commits¶
Tags can be applied to any commit in history:
Tag a specific commit using its hash¶
Tag a relative commit¶
Signing Tags¶
For extra security, create cryptographically signed tags:
Create a GPG-signed tag¶
Verify a signed tag¶
💡 Tip: Signed tags provide verification that the tag was created by a trusted source.
Managing Tags¶
Listing Tags¶
View the tags in your repository:
List all tags¶
List tags with patterns¶
List tags with annotations¶
Show verbose tag information¶
Viewing Tag Information¶
Inspect details about specific tags:
Show tag data¶
Display only the commit a tag points to¶
List tags that contain a specific commit¶
Searching and Filtering Tags¶
Find tags matching certain criteria:
Find tags matching a pattern¶
Find tags containing a specific commit¶
Find tags not containing a specific commit¶
Sorting Tags¶
Sort tags by version number or date:
Sort by version number (requires git 2.0+)¶
Sort by tag creation date¶
Reverse the sort order¶
Working with Tags¶
Checking Out Tags¶
Examine the code at a tagged release point:
View the repo at a specific tag¶
Create a new branch from a tag¶
⚠️ Warning: Checking out a tag puts you in a "detached HEAD" state. Create a branch if you need to make changes.
Comparing Tags¶
See differences between tagged versions:
Compare two tagged versions¶
Show commits between tags¶
Show file changes between tags¶
Deleting Tags¶
Remove tags when they're no longer needed:
Delete a local tag¶
Delete multiple tags¶
Renaming Tags¶
Git doesn't have a direct tag rename command, but you can:
Rename a tag - Step 1: Create new tag¶
Rename a tag - Step 2: Delete old tag locally¶
Rename a tag - Step 3: Delete old tag from remote¶
Rename a tag - Step 4: Push new tag to remote¶
Moving Tags¶
Point a tag to a different commit:
Move a tag to current HEAD (delete and recreate)¶
Move a tag to a specific commit (with force)¶
⚠️ Warning: Moving tags that have been pushed to a remote repository can cause confusion. Only do this if absolutely necessary.
Sharing Tags¶
Pushing Tags to Remote¶
By default, git push doesn't transfer tags:
Push a specific tag¶
Push all tags¶
Push all annotated tags¶
Fetching Tags¶
Get tags from remote repositories:
Fetch tags along with branches¶
Fetch all tags that aren't already present¶
Deleting Remote Tags¶
Remove tags from a remote repository:
Delete a remote tag¶
Alternative syntax:
Semantic Versioning¶
SemVer Format¶
Semantic Versioning provides a clear convention for version numbering:
Example: 2.4.1-alpha.1+20130313144700
Version Incrementing Rules¶
Guidelines for when to increment each version component:
- MAJOR: Incompatible API changes
- MINOR: Add functionality (backward-compatible)
- PATCH: Bug fixes (backward-compatible)
Example SemVer tagging workflow¶
gitGraph
commit
commit
commit tag: "v0.1.0"
commit
commit
commit tag: "v0.2.0"
branch hotfix
checkout hotfix
commit
checkout main
merge hotfix tag: "v0.2.1"
commit
commit
commit tag: "v1.0.0"
commit
commit tag: "v1.1.0"
branch breaking-changes
checkout breaking-changes
commit
commit
checkout main
merge breaking-changes tag: "v2.0.0"
Create initial release tag¶
Create patch release for bug fixes¶
Create minor release for new features¶
Create major release for breaking changes¶
Pre-release and Build Metadata¶
Use pre-release identifiers for pre-release versions:
Alpha version¶
Beta version¶
Release candidate¶
Release Workflows¶
GitFlow Release Workflow¶
Using GitFlow for structured releases:
gitGraph
commit
branch develop
checkout develop
commit
commit
branch release/v1.0
checkout release/v1.0
commit
checkout main
merge release/v1.0
commit tag: "v1.0.0"
checkout develop
merge release/v1.0
branch hotfix/v1.0.1
checkout hotfix/v1.0.1
commit
checkout main
merge hotfix/v1.0.1
commit tag: "v1.0.1"
checkout develop
merge hotfix/v1.0.1
commit
Step 1: Create a release branch¶
Step 2: Prepare the release¶
Step 3: Tag the release¶
Step 4: Merge to main¶
Step 5: Merge back to develop¶
Simple Tag-Based Releases¶
Simpler workflow using tags directly:
gitGraph
commit
commit
commit
commit tag: "v0.1.0"
commit
commit
commit tag: "v0.2.0"
commit
commit
commit tag: "v1.0.0"
Step 1: Ensure main branch is stable¶
Step 2: Tag the release¶
Step 3: Push the tag¶
GitHub Release Workflow¶
Creating releases on GitHub:
Step 1: Create and push a tag¶
Step 2: Create the release on GitHub¶
- Go to your repository on GitHub
- Navigate to "Releases" section
- Click "Create a new release"
- Select your tag
- Add release notes and artifacts
- Publish the release
Automating Releases with CI/CD¶
Using CI/CD pipelines for automated releases:
# Example GitHub Actions workflow
name: Create Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: |
npm install
npm run build
- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
💡 Tip: Automated release processes can include building, testing, creating release notes, and publishing artifacts.
Command Summary¶
| Operation | Command | Description |
|---|---|---|
| Create tag | git tag v1.0.0 | Create lightweight tag |
| Create annotated | git tag -a v1.0.0 -m "msg" | Create annotated tag |
| List tags | git tag | Show all tags |
| Show tag | git show v1.0.0 | Display tag details |
| Push tags | git push origin v1.0.0 | Push specific tag |
| Push all tags | git push --tags | Push all tags |
| Delete tag | git tag -d v1.0.0 | Remove local tag |
| Delete remote tag | git push origin --delete v1.0.0 | Remove remote tag |
| Checkout tag | git checkout v1.0.0 | Examine tagged version |
| Tag old commit | git tag v0.9.0 <commit-hash> | Tag previous commit |