How to tag a release version with git tag
To find a released version (such as v1.2.0) later by name, attach a tag to its commit with git tag -a. git push alone does not send tags to the remote, so you also need a separate push step after tagging. I checked the flow of tagging, listing, pushing to a remote, and deleting, using the actual output from a test environment.
The test environment is Ubuntu 24.04 with Git 2.43.0. I set the author name and email to example values (Neko <neko@example.com>). To keep the output the same every time, I set the commit and tag dates with the environment variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE. The push target was a bare repository (../remote.git) created in the same environment. I did not test pushing to hosting services such as GitHub, the GitHub Releases page, or tags signed with GPG (-s). I also did not check the behavior on Windows or macOS.
The repository before tagging
This repository has had its app.txt version raised to 1.0.0, 1.1.0, and 1.2.0. main has already been pushed, and there are no tags yet.
$ git tag
$ git log --oneline --decorate
0edd44a (HEAD -> main, origin/main) 1.2.0 の準備
f173986 1.1.0 の準備
62e82a6 1.0.0 の準備
f18407a 最初のコミット
Running git tag with no arguments lists the tags. Here it prints nothing.
Tagging the current commit with git tag -a
The scenario is releasing the current commit (0edd44a) as 1.2.0. Add -a and pass the message with -m.
$ git tag -a v1.2.0 -m "バージョン 1.2.0"
$ git tag
v1.2.0
$ git log --oneline --decorate
0edd44a (HEAD -> main, tag: v1.2.0, origin/main) 1.2.0 の準備
f173986 1.1.0 の準備
62e82a6 1.0.0 の準備
f18407a 最初のコミット
git log --decorate shows tag: v1.2.0 on 0edd44a. If you leave out -m, an editor opens for you to write the message (git tag official reference).
Passing the tag name to git show prints the tag information together with the commit it points to.
$ git show v1.2.0
tag v1.2.0
Tagger: Neko <neko@example.com>
Date: Wed Nov 11 11:00:00 2026 +0900
バージョン 1.2.0
commit 0edd44aff4507c1cf1cd64edbe0358d702e42bfa
Author: Neko <neko@example.com>
Date: Wed Nov 11 10:30:00 2026 +0900
1.2.0 の準備
diff --git a/app.txt b/app.txt
index 92cf5fa..3f0a2ab 100644
--- a/app.txt
+++ b/app.txt
@@ -1 +1 @@
-version: 1.1.0
+version: 1.2.0
The lines from the first tag v1.2.0 through the message are the tag information. Tagger: shows who created the tag, and Date: shows when it was created (11:00). The message follows below. These are recorded separately from the commit date (10:30).
The difference between annotated and lightweight tags
A tag created with -a is called an annotated tag. If you run git tag <name> without -a or -m, you get a lightweight tag. You can see the difference by checking the type of object the tag name points to with git cat-file -t.
$ git cat-file -t v1.2.0
tag
$ git cat-file -p v1.2.0
object 0edd44aff4507c1cf1cd64edbe0358d702e42bfa
type commit
tag v1.2.0
tagger Neko <neko@example.com> 1794362400 +0900
バージョン 1.2.0
The name of an annotated tag points to an object of type tag. That object contains the commit it points to (object), the person and time it was tagged (tagger), and the message.
I also created a lightweight tag for comparison.
$ git tag v1.2.0-light
$ git cat-file -t v1.2.0-light
commit
$ git show --stat v1.2.0-light
commit 0edd44aff4507c1cf1cd64edbe0358d702e42bfa
Author: Neko <neko@example.com>
Date: Wed Nov 11 10:30:00 2026 +0900
1.2.0 の準備
app.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
The name of a lightweight tag points directly to the commit. git show does not print a Tagger: line, so there is no record of who created the tag or when.

The official reference says annotated tags are for releases, and lightweight tags are for temporary personal bookmarks. Some commands, such as git describe, ignore lightweight tags by default. For release versions, use -a.
Delete the lightweight tag created for comparison with git tag -d.
$ git tag -d v1.2.0-light
Deleted tag 'v1.2.0-light' (was 0edd44a)
Tagging an older commit
You can also add a tag later to a past release that was not tagged at the time. Pass the commit you want to tag as the last argument. Here I specified HEAD~2 (two commits back) and HEAD~1 (one commit back).
$ git log --oneline
0edd44a 1.2.0 の準備
f173986 1.1.0 の準備
62e82a6 1.0.0 の準備
f18407a 最初のコミット
$ git tag -a v1.0.0 -m "バージョン 1.0.0" HEAD~2
$ git tag -a v1.1.0 -m "バージョン 1.1.0" HEAD~1
$ git log --oneline --decorate
0edd44a (HEAD -> main, tag: v1.2.0, origin/main) 1.2.0 の準備
f173986 (tag: v1.1.0) 1.1.0 の準備
62e82a6 (tag: v1.0.0) 1.0.0 の準備
f18407a 最初のコミット
If you try to create a tag with a name that already exists, the command stops with an error.
$ git tag -a v1.2.0 -m "やり直し"
fatal: tag 'v1.2.0' already exists
The official reference's "On Re-tagging" section says that if a tag has not been sent anywhere yet, you can recreate it with -f. Once it has been pushed, however, someone else may already have the old tag, so the safer approach is to use a different name such as X.1.
Listing tags in version order
I changed app.txt to 1.10.0, committed it, tagged that commit with v1.10.0, and then listed the tags.
$ echo "version: 1.10.0" > app.txt
$ git commit -q -am "1.10.0 の準備"
$ git tag -a v1.10.0 -m "バージョン 1.10.0"
$ git tag
v1.0.0
v1.1.0
v1.10.0
v1.2.0
By default, git tag lists tags sorted by name as text (when the tag.sort setting is not set). As a result, v1.10.0 appears before v1.2.0. To sort by version, use --sort=v:refname. Putting - before v:refname reverses the order so that newer versions come first (official reference for –sort).
$ git tag --sort=-v:refname
v1.10.0
v1.2.0
v1.1.0
v1.0.0
To filter by part of the name, pass a pattern with -l. To also see the messages, add -n.
$ git tag -l "v1.1*"
v1.1.0
v1.10.0
$ git tag -n
v1.0.0 バージョン 1.0.0
v1.1.0 バージョン 1.1.0
v1.10.0 バージョン 1.10.0
v1.2.0 バージョン 1.2.0
How many commits the current commit is past a tag
git describe shows the nearest tag to the current commit. On a commit that has a tag, it prints only the tag name.
$ git describe
v1.10.0
I add one commit and run it again.
$ echo "memo" > memo.txt
$ git add memo.txt && git commit -q -m "メモを追加"
$ git describe
v1.10.0-1-g284a895
This means the commit 284a895 is one commit past v1.10.0. The g stands for git and comes before the hash (git describe official reference).
Sending tags to the remote
A normal git push does not send tags (Pro Git's "Tagging" section, Japanese edition). If you push only the branch and then check the remote tags with git ls-remote --tags, nothing is listed.
$ git push origin main
To ../remote.git
0edd44a..284a895 main -> main
$ git ls-remote --tags origin
Sending one at a time
If you specify a tag name when pushing, only that tag is sent.
$ git push origin v1.10.0
To ../remote.git
* [new tag] v1.10.0 -> v1.10.0
$ git ls-remote --tags origin
82522d62b944ef0f929cce61a6abe30874f46ca4 refs/tags/v1.10.0
b5b3f8717aa900171bf4b6b09056191e5cd4ca82 refs/tags/v1.10.0^{}
refs/tags/v1.10.0 is the tag object, and the line ending in ^{} is the commit the tag leads to (revision specification official reference).
Sending annotated tags together with –follow-tags
If you push a branch with --follow-tags, annotated tags on commits reachable from the branch being pushed are also sent, as long as they are not already on the remote (git push official reference).
$ git push --follow-tags origin main
To ../remote.git
* [new tag] v1.0.0 -> v1.0.0
* [new tag] v1.1.0 -> v1.1.0
* [new tag] v1.2.0 -> v1.2.0
Only annotated tags are sent. After I created a lightweight tag named local-only and ran the same command, nothing was sent.
$ git tag local-only
$ git push --follow-tags origin main
Everything up-to-date
Sending all tags with –tags
With --tags, all local tags are sent, including lightweight tags.
$ git push origin --tags
To ../remote.git
* [new tag] local-only -> local-only
--tags also sends lightweight tags that you created only as personal bookmarks. If you want to send only release tags, specify the names or use --follow-tags.
Deleting a tag that was pushed by mistake
Delete a local tag with git tag -d, and a remote tag with git push origin --delete. Deleting a tag only locally leaves the remote tag in place.
$ git tag -d local-only
Deleted tag 'local-only' (was 284a895)
$ git push origin --delete local-only
To ../remote.git
- [deleted] local-only
$ git ls-remote --tags origin
5f681d6e8220f2584ccdd45eda4fffe6fa805352 refs/tags/v1.0.0
62e82a67302f6a3e034f9d293d9b6abad9f6cb26 refs/tags/v1.0.0^{}
855e6c05fc2181e4babe87adb707c2eef0ae5f91 refs/tags/v1.1.0
f17398600c110983fe79287d3d768b96d827bbec refs/tags/v1.1.0^{}
82522d62b944ef0f929cce61a6abe30874f46ca4 refs/tags/v1.10.0
b5b3f8717aa900171bf4b6b09056191e5cd4ca82 refs/tags/v1.10.0^{}
093f427a718c396a5c11ba369d3a7947994516a0 refs/tags/v1.2.0
0edd44aff4507c1cf1cd64edbe0358d702e42bfa refs/tags/v1.2.0^{}
Only the four release tags remain on the remote.
Checking out a tagged version
When you clone the remote, the tags come with it. Passing a tag name to git switch --detach lets you check out the contents of that version.
$ git clone -q ../remote.git ../clone && git -C ../clone tag
v1.0.0
v1.1.0
v1.10.0
v1.2.0
$ git -C ../clone switch -q --detach v1.0.0 && git -C ../clone status | head -1 && cat ../clone/app.txt
HEAD detached at v1.0.0
version: 1.0.0
HEAD detached at v1.0.0 means you are on the commit the tag points to, not on a branch. app.txt now has the contents it had at version 1.0.0.




