Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Git & GitHub - Tagging

How to tag commits in Git

Tagging in Git is a way to mark specific points in your repository's history as important. This guide explains how to tag commits in Git, including creating, listing, and managing tags.

Key Points:

  • Tags are used to mark important points in the repository history, such as releases.
  • Git supports lightweight tags and annotated tags.
  • Tags can be pushed to and deleted from remote repositories.

Creating Tags

There are two types of tags in Git: lightweight tags and annotated tags.

Lightweight Tags

A lightweight tag is a simple pointer to a specific commit.


# Create a lightweight tag
$ git tag v1.0
                

Annotated Tags

An annotated tag stores extra metadata such as the tagger's name, email, date, and a message. Annotated tags are recommended because they contain more information.


# Create an annotated tag
$ git tag -a v1.0 -m "Version 1.0 release"
                

Listing Tags

To list all tags in your repository, use the git tag command.


# List all tags
$ git tag
                

You can also use a pattern to list tags that match a specific criteria.


# List tags matching a pattern
$ git tag -l "v1.*"
                

Viewing Tag Details

To view details of a specific tag, use the git show command followed by the tag name.


# View details of an annotated tag
$ git show v1.0
                

Pushing Tags to a Remote Repository

By default, tags are not pushed to remote repositories when you push commits. To push tags, use the git push command followed by the remote name and the tag name.


# Push a specific tag to the remote repository
$ git push origin v1.0

# Push all tags to the remote repository
$ git push origin --tags
                

Deleting Tags

To delete a tag locally, use the git tag -d command followed by the tag name.


# Delete a local tag
$ git tag -d v1.0
                

To delete a tag from a remote repository, use the git push command with the --delete option.


# Delete a remote tag
$ git push origin --delete tag v1.0
                

Summary

This guide covered how to tag commits in Git, including creating lightweight and annotated tags, listing tags, viewing tag details, pushing tags to a remote repository, and deleting tags. Tagging is a useful feature for marking important points in your project's history and managing releases.