0

Is it possible to do a GIT clone on the a branch which name is the greatest in a sorted list given a specific prefix("release")? We have release branches like:

release/0.0.1
release/0.0.2
release/0.0.3

At the moment we have to specifically tell what branch to pull witch does not work with with the automated workflow we try to set up:

git clone -b release/0.0.3 --single-branch git@bitbucket.org:comp/proj.git /var/www/html #
Sultanen
  • 3,084
  • 5
  • 25
  • 46
  • Well, since a branch in git is simply a movable label on a given commit and doesn't carry any additional info, then the answer is probably "no, you can't". But if you change "branch" to "named tag", then probably it's possible to create a viable solution for you. – user3159253 Jan 19 '16 at 11:39
  • Or simply specify "latest branch" somehow differently, e.g. like "a branch with the latest commit", or "a branch which name is the greatest in the sorted list". – user3159253 Jan 19 '16 at 11:41
  • Thanks, ill edit the question to use "a branch which name is the greatest in the sorted list". thats probably the best way to go then – Sultanen Jan 19 '16 at 11:43
  • Take a look at http://stackoverflow.com/q/1404796/1700321. – Aleksandr M Jan 19 '16 at 11:50
  • Thanks alot for the link! – Sultanen Jan 20 '16 at 21:27

1 Answers1

0

This did the trick for me:

git ls-remote --heads | grep -o 'refs/heads/release/[0-9]*\.[0-9]*\.[0-9]*' | sort -r | grep -o '[0-9]*\.[0-9]*\.[0-9]*' -m 1

returns "0.0.3"

Sultanen
  • 3,084
  • 5
  • 25
  • 46