How to automatically checkout the latest tag of a Git repository

Now that you know How to automatically tag a Git repository an interesting command to know about is “How to automatically checkout the latest tag of a Git repository”. Let’s imagine that you want to automatically release a stable version of your product (that have dependencies or not) based on the latest version available on your repository.

An easy way to do it is to follow the following steps:

# Get new tags from the remote
$ git fetch --tags

# Get the latest tag name
$ latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)

# Checkout the latest tag
$ git checkout $latestTag

7 thoughts on “How to automatically checkout the latest tag of a Git repository”

  1. This will help out fantastically for deploying Amazon S3 websites that are managed via version control with multiple developers on hand! I’m going to write an article on it, and I’ll be sure to mention you, Julian. Thanks a ton!

Leave a Reply

Your email address will not be published. Required fields are marked *