Home·Terminal commands

git tag

git

Usage

git tag [-a] <name> [<commit>]

Puts a name such as a version on a commit; a plain git push does not carry tags, so the tag has to be pushed by name.

Common flags

FlagMeaning
-aannotated tag with a message, author and date
-m "<msg>"the message for -a
-l "<pattern>"list tags matching a pattern
-d <name>delete a tag locally
-fmove an existing tag
--sort=-creatordatenewest tag first

Examples

git tag -a v1.2.0 -m "release 1.2.0"

marks the current commit as a release

git push origin v1.2.0

the separate step that puts the tag on the server

git tag -d v1.2.0

deletes it locally; the server keeps its copy

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git tag do?

Puts a name such as a version on a commit; a plain git push does not carry tags, so the tag has to be pushed by name.

Q. How do I type it?

git tag [-a] <name> [<commit>] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-tag