乐闻世界logo
搜索文章和话题

How to Create Tags in Git?

2024年7月4日 00:34

Creating tags in Git is a highly practical feature that helps you mark release versions or significant milestones. Git offers two types of tags: lightweight tags and annotated tags.

Lightweight Tags

Lightweight tags function similarly to a branch that remains fixed; they simply refer to a specific commit. Creating lightweight tags is straightforward. Assuming you are on the commit you wish to tag, you can create one using the following command:

bash
git tag <tagname>

For example, to tag a version named v1.0, you can use:

bash
git tag v1.0

Annotated Tags

Annotated tags provide more detailed information, including the creator's details, date, message, and GPG signing capability. This is the recommended approach for creating tags because it preserves additional historical context. The command to create annotated tags is:

bash
git tag -a <tagname> -m "your message"

For instance, to create an annotated tag named v1.0 with a release note, you can use:

bash
git tag -a v1.0 -m "Release version 1.0"

Viewing Tags

After creating tags, you can list all tags using the following command:

bash
git tag

Pushing Tags to Remote Repository

By default, tags are not pushed to the remote repository with git push. To push a specific tag to the remote repository, use:

bash
git push origin <tagname>

To push all local tags to the remote repository at once, use:

bash
git push origin --tags

In summary, using lightweight and annotated tags allows you to establish clear milestones at critical project points, which is highly beneficial for version control and project management.

标签:Git