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.
Checking out version: XX
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).
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 .
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.
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.
# 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
git describe --tags
should give you info.
bash/ shell script:
#!/bin/bash ... latesttag=$(git describe --tags) echo checking out ${latesttag} git checkout ${latesttag}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With