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:
bashgit tag <tagname>
For example, to tag a version named v1.0, you can use:
bashgit 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:
bashgit tag -a <tagname> -m "your message"
For instance, to create an annotated tag named v1.0 with a release note, you can use:
bashgit tag -a v1.0 -m "Release version 1.0"
Viewing Tags
After creating tags, you can list all tags using the following command:
bashgit 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:
bashgit push origin <tagname>
To push all local tags to the remote repository at once, use:
bashgit 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.