How to checkout a git tag

Git tags are created to mark a release candidate. Because it points directly to a commit in the git history and will not change.

But sometimes we need to checkout a remote tag to our local. You can achieve this by fetching it from remote and checkout it as a branch on local.

Here is how we can achieve this.

Fetch git tags

The first thing you need is to fetch the git tag to your local. You can do this by using the git fetch command with --all and --tags arguments.

$ git fetch --all --tags

Checkout tag as a branch

The next step is to checkout a specific tag as a branch with git checkout command with the tag name and new branch name.

$ git checkout tags/<tag_name> -b <branch_name>

Now you can test the code from a tag on your local branch and make updates as well.