Intro

Git Tags are similar to branches, with the main difference being that once a tag is made there’s not further commit history, i.e. no changes can be committed to that tag.

Why?

Since tags can’t be updated once they’re made, they are great references to a specific point in the commit history of a project, serving as a reference that makes semantic sense at that point in time. For this reason, they’re often used for versioning. E.g. V1.045

Types

Lightweight Tags

These are quick and are mainly for internal, read private, use.

Creating a lightweight tag

git tag <tagname>

Annotated Tags

These carry a bit more in the metadata. Info like the name of the tagger, their email, the date…etc. These are meant for public-facing use such as a public release version of a program.

Creating

Just like before but with the -a flag.

git tag -a <tagname>
  • Can even add a message using -m just like with commits.

Pushing Tags to Remote

By default git push doesn’t push any tags. However, we can do so explicitly. For example, the following will push the specified tag to the remote origin:

git push origin v.1045

“To push multiple tags simultaneously pass the --tags option to git push command. When another user clones or pulls a repo they will receive the new tags.”


References