To create a lightweight tag, use the following command:
git tag <tag-name> <commit-hash>
Replace <tag-name>
with the name you want to give the tag, and <commit-hash>
with the commit you want to tag. For example, to create a lightweight tag named "v1.0" for the current commit, you would run:
git tag v1.0
To create an annotated tag, use the -a
(or --annotate
) option with the git tag
command. This allows you to include additional metadata, such as a tagging message.
git tag -a <tag-name> -m "<tag-message>" <commit-hash>
Replace <tag-name>
with the name you want to give the tag, <tag-message>
with a brief description of the tag, and <commit-hash>
with the commit you want to tag. For example, to create an annotated tag named "v1.0" with a tagging message, you would run:
git tag -a v1.0 -m "Release version 1.0" <commit-hash>
Verifying Tag Creation
After creating a tag, you can verify that it was created successfully by running the git tag
command again:
git tag
This will display a list of all the tags in your repository, including the one you just created.
By default, when you create a tag, it is only stored locally in your repository. To share the tag with others, you need to push it to the remote repository. You can do this using the following command:
git push origin <tag-name>
Replace <tag-name>
with the name of the tag you want to push. If you want to push all of your tags to the remote repository, you can use the following command:
git push origin --tags
This will push all of the tags in your local repository to the remote repository.
By understanding how to create and annotate Git tags, you can effectively manage the versioning and release history of your project.