my-notes

git_tagging

1 min read

git tagging

Create and manage version tags.


🏷️ Creating Tags

Lightweight Tag

git tag v1.0.0

Creates simple tag pointing to current commit.


git tag -a v1.0.0 -m "Release version 1.0.0"

Creates tag with message, author, and date information.


Tag Specific Commit

git tag -a v1.0.0 abc1234 -m "Release version 1.0.0"

Creates tag on a specific commit hash.


Signed Tag

git tag -s v1.0.0 -m "Signed release"

Creates GPG-signed tag.


πŸ“‹ View Tags

List All Tags

git tag

Shows all tags in repository.


List Tags with Pattern

git tag -l "v1.*"

Lists tags matching pattern.


Show Tag Details

git show v1.0.0

Shows tag information and associated commit.


List Tags with Messages

git tag -n

Lists tags with first line of message.


List with Full Messages

git tag -n99

Lists tags with up to 99 lines of message.


πŸ“Š Tag Types

graph TD
    A[Git Tags] --> B[Lightweight]
    A --> C[Annotated]
    B --> D[Just a pointer to commit]
    C --> E[Full Git object with metadata]
    C --> F[Recommended for releases]

⬆️ Sharing Tags

Push Single Tag

git push origin v1.0.0

Pushes specific tag to remote.


Push All Tags

git push origin --tags

Pushes all local tags to remote.


Push Only Annotated Tags

git push origin --follow-tags

Pushes commits and annotated tags only.


βœ… Checkout Tags

Checkout Tag (Detached HEAD)

git checkout v1.0.0

Switches to tag. Warning: detached HEAD state.


Create Branch from Tag

git checkout -b release-1.0 v1.0.0

Creates new branch starting from tag.


πŸ—‘οΈ Deleting Tags

Delete Local Tag

git tag -d v1.0.0

Removes tag from local repository.


Delete Remote Tag

git push origin --delete v1.0.0

Removes tag from remote repository.


Alternative Remote Delete

git push origin :refs/tags/v1.0.0

Alternative syntax to delete remote tag.


πŸ”„ Fetch Remote Tags

Fetch All Tags

git fetch --tags

Downloads all tags from remote.


Fetch and Prune Tags

git fetch --prune --prune-tags

Fetches and removes locally deleted remote tags.


✍️ Semantic Versioning

Format: MAJOR.MINOR.PATCH

Change Version When
Major v2.0.0 Breaking changes
Minor v1.1.0 New features (backwards compatible)
Patch v1.0.1 Bug fixes

Pre-release Tags

git tag -a v2.0.0-beta.1 -m "Beta release"

Creates pre-release version tag.


Release Candidate

git tag -a v2.0.0-rc.1 -m "Release candidate 1"

Creates release candidate tag.


πŸ’‘ Tips

Find Tag for Commit
git tag --contains abc1234
Latest Tag
git describe --tags --abbrev=0
Describe Current Position
git describe --tags

Shows: v1.0.0-5-gabc1234 (5 commits after v1.0.0)



#git #tag #version #release #advanced

Built with mdgarden