Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Checkout Latest Tag

Tags:

git

bash

shell

tags

I'm writing a shell script and I'm looking to checkout the latest version of repo. Specifically I want to break this process apart into multiple steps.

  1. I want to save the repositories latest tag into a variable
  2. Print out Checking out version: XX
  3. Checkout the latest tag

I've seen similar questions but I don't see how to save the name of the tag into a variable (probably because I'm a noob with shell scripts).

like image 1000
BFTrick Avatar asked Jul 01 '13 21:07

BFTrick


People also ask

How do I pull latest tag?

JB. JB. Returns the latest tag in the current branch. To get the latest annotated tag which targets only the current commit in the current branch, use git describe --exact-match --abbrev=0 .

Can I checkout a tag in git?

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.

How do I get the latest tag in github?

In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.


2 Answers

# Get new tags from remote git fetch --tags  # Get latest tag name latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)  # Checkout latest tag git checkout $latestTag 
like image 139
Josef Ježek Avatar answered Sep 29 '22 11:09

Josef Ježek


git describe --tags should give you info.

bash/ shell script:

#!/bin/bash ... latesttag=$(git describe --tags) echo checking out ${latesttag} git checkout ${latesttag} 
like image 43
exussum Avatar answered Sep 29 '22 09:09

exussum