practical guide to working with tags in Git:
Create a tag
To create a tag in Git, use the git tag
command followed by the tag name. For example, to create a tag called v1.0
for the current commit, run:
git tag v1.0
This will create a lightweight tag at the current commit.
To create an annotated tag with additional information such as a tag message or a signature, use the -a
option. For example:
git tag -a v1.0 -m "Release version 1.0"
This will create an annotated tag at the current commit with the tag message “Release version 1.0”.
List tags
To list all tags in the repository, use the git tag
command:
git tag
This will list all tags in the repository.
To show the details of a specific tag, use the git show
command followed by the tag name. For example:
git show v1.0
This will show the details of the v1.0
tag.
Delete tags
To delete a tag, use the git tag -d
command followed by the tag name. For example:
git tag -d v1.0
This will delete the v1.0
tag.
Push tags to remote
To push tags to a remote repository, use the git push
command with the --tags
option. For example:
git push --tags
This will push all tags in the repository to the remote repository.
To push a specific tag, use the git push
command followed by the tag name. For example:
git push origin v1.0
This will push the v1.0
tag to the origin
remote repository.
Checkout tags
To checkout a specific tag, use the git checkout
command followed by the tag name. For example:
git checkout v1.0
This will checkout the code at the commit associated with the v1.0
tag.
That’s it! These are some practical examples of how to work with tags in Git.