git origin
remove git tags
delete local tags
git tutorial
git command-line

How to remove all git origin and local tags?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Removing every Git tag from both your local repository and the origin remote is straightforward, but it is also destructive. Tags are often used for releases, deployments, and audit trails, so the safe approach is to preview them first, delete local tags, delete remote tags, and then verify that nothing stale remains.

Preview Tags Before Deleting Anything

Start by listing the tags that exist locally and on origin. This gives you a checkpoint and helps you avoid deleting release tags by accident.

bash
git tag -l
git ls-remote --tags --refs origin

The --refs flag matters for remote output because it suppresses the extra dereferenced lines that annotated tags can produce. Without it, the same tag can appear twice and complicate deletion loops.

If the tag list contains values you must keep, stop here and delete only the specific tags you intend to remove.

Delete All Local Tags

Local tag deletion is easy because git tag -d accepts one tag name at a time. A shell loop works well across systems:

bash
git tag -l | while read -r tag; do
  [ -n "$tag" ] && git tag -d "$tag"
done

This removes only the local tag references. It does not touch origin, and it does not rewrite commit history.

If you run git tag -l again after the loop, the output should be empty.

Delete All Remote Tags on origin

Remote tag deletion uses a push that removes the ref from the server. The easiest reliable pattern is to list remote tags and push a deletion for each one:

bash
git ls-remote --tags --refs origin | awk '{print $2}' | sed 's#refs/tags/##' | while read -r tag; do
  [ -n "$tag" ] && git push origin ":refs/tags/$tag"
done

Each push removes one tag ref from origin. This is safer than relying on shell expansion from local tags because the remote may contain tags that no longer exist locally.

After the deletion loop finishes, verify the remote state:

bash
git ls-remote --tags --refs origin

If the command prints nothing, the remote no longer has tag refs.

Clean Up Stale Tag References

In shared repositories, stale refs can linger in local metadata until you fetch and prune. After deleting the remote tags, run:

bash
git fetch origin --prune --prune-tags

Then confirm both views again:

bash
git tag -l
git ls-remote --tags --refs origin

This final check matters when automation or another developer may have recreated tags during your cleanup window.

Deleting a Single Tag Is the Same Pattern

If you decide that deleting every tag is too broad, the per-tag commands are the same operations applied selectively:

bash
git tag -d v1.2.3
git push origin :refs/tags/v1.2.3

That pattern is worth remembering because mass deletion is rarely the normal day-to-day task.

Common Pitfalls

  • Forgetting that tags are often part of release workflows. Deleting them can break deployment jobs, changelog generation, or package publishing.
  • Using git ls-remote --tags origin without --refs. Annotated tags can appear more than once and make loops noisy or misleading.
  • Deleting local tags first and assuming the remote will match automatically. Local and remote tag refs are independent.
  • Skipping the verification step. Another process may recreate tags, or a protected remote may reject some deletions.
  • Running destructive tag cleanup on the wrong remote. Check that origin is really the server you intend to modify.

Summary

  • Preview local and remote tags before deleting them.
  • Remove local tags with git tag -d in a loop.
  • Remove remote tags by pushing deletions to origin for each tag ref.
  • Run git fetch origin --prune --prune-tags so stale references do not linger locally.
  • Treat tag cleanup as destructive repository maintenance, not as a harmless cosmetic change.

Course illustration
Course illustration

All Rights Reserved.