Now that you understand the basics of Git tags, let's dive into the process of creating and applying them in your Git repository.
As mentioned earlier, you can create two types of Git tags: lightweight and annotated. Here's how you can create each type:
To create a lightweight tag, use the following command:
git tag v1.0.0
This will create a lightweight tag named v1.0.0
that points to the current commit.
To create an annotated tag, use the -a
(annotate) option and provide a message with the -m
flag:
git tag -a v1.0.0 -m "Release version 1.0.0"
This will create an annotated tag named v1.0.0
with the message "Release version 1.0.0".
After creating a tag, you can apply it to a specific commit. This is useful if you want to tag a commit that is not the current HEAD.
To apply a tag to a specific commit, use the following command:
git tag v1.0.0 <commit-hash>
Replace <commit-hash>
with the full or partial commit hash of the commit you want to tag.
Once you have created your tags, you can push them to a remote repository so that other collaborators can access them. To push tags, use the following command:
git push origin --tags
This will push all your local tags to the remote repository.
Checking Out Tagged Commits
To check out a tagged commit, you can use the git checkout
command:
git checkout v1.0.0
This will switch your working directory to the state of the repository at the time the v1.0.0
tag was created.
By understanding how to create, apply, and manage Git tags, you can effectively track and reference important milestones in your project's development.