How to fetch all tags in Git

Fetching tags downloads version markers and release pointers from remote repository, ensuring local repository has complete release history and version references. As the creator of CoreUI, a widely used open-source UI library, I’ve managed semantic versioning and release tags throughout my 25 years of development experience. The most reliable approach is using git fetch –tags to download all tags or git fetch –prune –prune-tags to synchronize and remove deleted tags. This method ensures complete tag synchronization, handles annotated and lightweight tags, and maintains clean tag references matching remote state.

Use git fetch –tags to download all tags from remote repository.

# Fetch all tags from default remote (origin)
git fetch --tags

# Fetch all tags from specific remote
git fetch --tags upstream

# Fetch all tags and branches
git fetch --all --tags

# Fetch tags and prune deleted tags
git fetch --prune --prune-tags

# Fetch tags with verbose output
git fetch --tags --verbose

View and inspect fetched tags:

# List all local tags
git tag

# List tags with pattern matching
git tag -l 'v1.*'
# Output:
#   v1.0.0
#   v1.0.1
#   v1.1.0
#   v1.2.0

# Show tag details with annotation
git show v1.0.0

# List tags with commit messages
git tag -n
# Output:
#   v1.0.0    Release version 1.0.0
#   v1.0.1    Bug fixes for production

# Show tag commit hash
git rev-parse v1.0.0

# List tags sorted by version
git tag --sort=version:refname

# List tags sorted by creation date
git tag --sort=-creatordate

Working with specific tags:

# Fetch and checkout specific tag
git fetch --tags
git checkout v1.0.0

# Create branch from tag
git checkout -b hotfix-v1.0.0 v1.0.0

# View differences between tags
git diff v1.0.0 v1.1.0

# View commits between tags
git log v1.0.0..v1.1.0

# View compact history between tags
git log v1.0.0..v1.1.0 --oneline --decorate

# List files changed between tags
git diff --name-only v1.0.0 v1.1.0

Fetch tags with advanced options:

# Fetch only tags without branches
git fetch origin 'refs/tags/*:refs/tags/*'

# Fetch specific tag
git fetch origin tag v2.0.0

# Fetch all remote references including tags
git fetch origin '+refs/heads/*:refs/remotes/origin/*' '+refs/tags/*:refs/tags/*'

# Force fetch tags (overwrites local tags)
git fetch --tags --force

# Fetch shallow tags for large repositories
git fetch --depth=1 --tags

# Fetch tags without fetching branch commits
git ls-remote --tags origin

Synchronize tags with remote:

# Remove local tags that don't exist on remote
git fetch --prune --prune-tags origin

# Delete specific local tag
git tag -d v1.0.0

# Delete remote tag
git push origin --delete tag v1.0.0

# Fetch after remote tag deletion
git fetch --prune --prune-tags

# Push all local tags to remote
git push origin --tags

# Push specific tag to remote
git push origin v1.0.0

Tag management workflow:

# Fetch all tags and view releases
git fetch --tags
git tag -l

# Find which tag contains specific commit
git describe --tags --contains abc123

# Find most recent tag
git describe --tags --abbrev=0

# Find tag on current commit
git describe --exact-match --tags HEAD

# View tag creation date
git log -1 --format=%ai v1.0.0

# List tags with creation date
git for-each-ref --sort=creatordate --format '%(refname:short) %(creatordate:short)' refs/tags

Automated tag fetching in scripts:

#!/bin/bash
# fetch-and-list-tags.sh

echo "Fetching all tags from remote..."
git fetch --tags --prune --prune-tags

echo "Latest 10 tags:"
git tag --sort=-version:refname | head -n 10

echo "\nLatest tag:"
LATEST_TAG=$(git describe --tags --abbrev=0)
echo "$LATEST_TAG"

echo "\nTag details:"
git show "$LATEST_TAG" --quiet

Compare local and remote tags:

# List all remote tags
git ls-remote --tags origin

# Compare local and remote tags
comm -3 <(git tag | sort) <(git ls-remote --tags origin | awk '{print $2}' | sed 's|refs/tags/||' | sort)

# Find tags only on remote
git ls-remote --tags origin | awk '{print $2}' | sed 's|refs/tags/||' | while read tag; do
  if ! git tag | grep -q "^${tag}$"; then
    echo "$tag (remote only)"
  fi
done

# Find tags only locally
git tag | while read tag; do
  if ! git ls-remote --tags origin | grep -q "refs/tags/${tag}$"; then
    echo "$tag (local only)"
  fi
done

Configure automatic tag fetching:

# Configure Git to fetch tags automatically
git config --global remote.origin.tagOpt --tags

# Or add to .git/config
[remote "origin"]
    url = https://github.com/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    tagOpt = --tags

# Disable automatic tag fetching
git config remote.origin.tagOpt --no-tags

# Fetch with default config
git fetch

Working with annotated vs lightweight tags:

# Fetch all tags
git fetch --tags

# Check if tag is annotated or lightweight
git cat-file -t v1.0.0
# Output: tag (annotated) or commit (lightweight)

# View annotated tag message
git tag -l -n9 v1.0.0

# Create and push annotated tag
git tag -a v2.0.0 -m "Release version 2.0.0"
git push origin v2.0.0

# Create and push lightweight tag
git tag v2.0.0-beta
git push origin v2.0.0-beta

Here git fetch –tags downloads all tags from remote repository including both annotated and lightweight tags. The –prune-tags option removes local tags that have been deleted from remote repository. The git tag command lists all local tags with various sorting and filtering options. The git ls-remote –tags queries remote repository for available tags without downloading them. The git describe finds the most recent tag reachable from current commit. The tagOpt configuration controls whether tags are fetched automatically with branches. The git show displays tag annotation, tagger information, and tagged commit for annotated tags.

Best Practice Note:

This is the tag management workflow we use in CoreUI to synchronize release tags and maintain version consistency across team members. Fetch tags regularly before checking out specific versions to ensure you have complete release history, use semantic versioning for tags to maintain clear version progression, and prefer annotated tags over lightweight tags for releases as they contain tagger information and release notes for better documentation.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author