Last active
August 13, 2018 16:52
-
-
Save GrayedFox/de2bf1dd13a124557f6433b7d6dabb62 to your computer and use it in GitHub Desktop.
Bash function to clone the latest tagged version of a repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
LATEST_TAG="$(curl --silent https://api.github.com/repos/$1/$2/tags | grep -Po '"name": "\K.*?(?=")' | head -1)" | |
echo "Cloning $LATEST_TAG" | |
if [ "$3" = "-https" ]; then | |
git clone https://github.com/$1/$2.git --branch $LATEST_TAG | |
else | |
git clone [email protected]:$1/$2.git --branch $LATEST_TAG | |
fi | |
# Usage (defaults to cloning with SSH): | |
# git clone-latest asdf-vm asdf | |
# git clone-latest asdf-vm asdf https | |
# Notes: | |
# This will result in cloning the repository and detaching the head, as per the docs. | |
# The latest tag is not necessarily the latest release: this command simply takes the top most entry of the | |
# JSON response. If wanting to check the order and see all available tags do: | |
# | |
# curl --silent https://api.github.com/repos/$USER/$REPO/tags | grep -Po '"name": "\K.*?(?=")' |
Important: the latest tag is not necessarily the latest release!
This command simply takes the top most entry of the the JSON response. If wanting to check the order and see all available tags do:
curl --silent https://api.github.com/repos/$USER/$REPO/tags | grep -Po '"name": "\K.*?(?=")'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this will result in cloning the repository and detaching the head, as per the docs.