Source From HerePreface
When working with Git, it is quite common for developers to create tags in order to have reference points in your development.
Tags are created in order to have references to release versions for example. Furthermore, tags are Git objects meaning that they can be checked out like you would check out a branch or a commit for example.
In this tutorial, we are going to see how you can checkout Git tags easily.
Checkout Git Tag
In order to checkout a Git tag, use the “git checkout” command and specify the tagname as well as the branch to be checked out:
Note that you will have to make sure that you have the latest tag list from your remote repository. To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options:
You can inspect the state of your branch by using the “git log” command. Make sure that the HEAD pointer (the latest commit) is pointing to your annotated tag.
Checkout latest Git tag
In some cases, you may be interested in checking out the latest Git tag of your repository. In order to checkout the latest Git tag, first update your repository by fetching the remote tags available.
As you can see, you retrieve the tag from your remote repository. Then, retrieve the latest tag available by using the “git describe” command:
That’s it! You have successfully checkout the latest Git tag available in a new branch.
* 2.6 Git 基礎 - 標籤