Skip to content
LatchkeyLatchkey home

git tag: Usage, Options & Common CI Errors

git tag marks a specific commit, usually a release, with a permanent name.

Tags are how release pipelines pin versions. Remember that tags are not pushed by default.

What it does

git tag creates a lightweight or annotated tag pointing at a commit. Annotated tags (-a) store a tagger, date, and message; lightweight tags are just a name.

Common usage

Terminal
git tag                       # list tags
git tag v1.2.0                # lightweight tag on HEAD
git tag -a v1.2.0 -m "Release 1.2.0"
git push origin v1.2.0        # tags are NOT pushed by default
git tag -d v1.2.0             # delete locally

Options

FlagWhat it does
-a / --annotateCreate an annotated tag
-m <msg>Tag message (implies annotated)
-d / --deleteDelete a tag locally
-l / --list <pattern>List tags matching a pattern
-f / --forceMove an existing tag

Common errors in CI

fatal: tag 'vX' already exists - re-tagging needs -f, and the remote tag also needs git push --force origin vX (or delete-then-push). Tags missing on the runner usually means a shallow clone or that git fetch --tags was not run; set fetch-depth: 0.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git tag: Usage, Options & Common CI Errors?
Tags are how release pipelines pin versions. Remember that tags are not pushed by default.
What it does?
git tag creates a lightweight or annotated tag pointing at a commit. Annotated tags (-a) store a tagger, date, and message; lightweight tags are just a name.
Common errors in CI?
fatal: tag 'vX' already exists - re-tagging needs -f, and the remote tag also needs git push --force origin vX (or delete-then-push). Tags missing on the runner usually means a shallow clone or that git fetch --tags was not run; set fetch-depth: 0.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card