Black Friday sale: 30% off Pro and Unlimited, until 22 December

How to push a single tag in Git

Check which commit a local tag points to, preview the push, and confirm that the same tag landed on the remote.

Your release needs v1.4.0. You also have other local tags and another commit on the branch. Check where the release tag points, then publish that exact tag.

The short version is git push origin refs/tags/v1.4.0. The full ref avoids pushing a branch with the same name by mistake. The steps below also check the tag first.

Check what the tag points to

Run the commands from your repository in the same terminal. Replace v1.4.0 with your local tag and origin with your publishing remote.

ref=refs/tags/v1.4.0
tag_oid=$(git show-ref \
  --verify --hash "$ref") &&
commit_oid=$(git rev-parse \
  --verify "$tag_oid^{commit}") &&
git log -1 --oneline \
  "$commit_oid" &&
printf '%s\n' \
  "$tag_oid" "$commit_oid"

Check the commit subject and ID. For an annotated tag, the last two lines show the saved tag object ID and the commit ID, in that order. Keep both for the remote check. For a lightweight tag pointing to a commit, the two IDs match. Stop if the commands fail or the tag points to the wrong commit.

Preview the push

git remote get-url --all origin &&
git remote get-url --push \
  --all origin

The first command lists the fetch URLs. The second lists the push URLs. Continue only if each command prints one URL and both point to the repository where you intend to publish. Otherwise, use a named remote with one fetch URL and one push URL for that repository, then check again.

git push --dry-run --no-verify \
  --no-follow-tags \
  --recurse-submodules=no \
  origin "${tag_oid:?}:${ref:?}"

The preview uses --no-verify to skip the local pre-push hook and avoid any changes it might make. For a new tag, look for a single update with the saved object ID on the left.

 * [new tag] <tag-object-id> -> v1.4.0

The saved object ID pins what you reviewed, even if the local tag moves. The destination is the tag name on the remote. The :? checks stop the command if either value is missing. --no-follow-tags keeps Git from adding other annotated tags, and --recurse-submodules=no keeps the push in this repository.

If Git says the tag is already up to date, skip to verification. If Git rejects the push because the tag already exists with a different ID, leave it in place while you confirm which commit belongs to the release.

If you mean to send branch work too, preview the branch push separately. If a branch push can trigger a deploy, see how to stop accidental pushes to production.

Push and verify the tag

Remove --dry-run and --no-verify for the real push. Git runs your local pre-push hook, if configured, before sending the tag.

git push --no-follow-tags \
  --recurse-submodules=no \
  origin "${tag_oid:?}:${ref:?}"

Git sends any objects needed by the tag, including its commit if the remote is missing it. The only ref this push updates is the tag.

Read the tag back from the same remote. Match the saved ID and full ref on one line.

remote_tags=$(
  git ls-remote --exit-code \
    --tags origin \
    "${ref:?}" "$ref^{}"
) &&
tag_row=$(printf '%s\t%s' \
  "${tag_oid:?}" "$ref") &&
printf '%s\n' "$remote_tags" |
  grep -Fx "$tag_row" &&
if [ "$tag_oid" != \
  "${commit_oid:?}" ]; then
  commit_row=$(printf '%s\t%s' \
    "$commit_oid" "$ref^{}")
  printf '%s\n' "$remote_tags" |
    grep -Fx "$commit_row"
fi

A lightweight tag should print one matching row. An annotated tag should print two: the tag object ID beside refs/tags/v1.4.0 and the commit ID beside the ref ending in ^{}. If any expected row is missing, stop and check the publishing remote and tag name.

Optional tag pushes

Tag pushes in push& (Pushand) are optional and start off. See the safety settings.

More Git how-tos