mattdipasquale mattdipasquale - 1 year ago 77
Git Question

How do I get Git's latest stable release version number?

I'm writing a script:

To get Git's latest stable release version number, I do:

LSR_NUM=$(curl -silent | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p')

2 Questions:

  1. Refactor my code: Is there a better way programmatically to do this?

  2. This works now, but it's brittle: if
    the web page at
    changes, the line above may stop

    PHP has a reliable URL for getting
    the latest release version:

    Is there something like this for
    Git? This comes close:

Answer Source

I'd just do this:

git ls-remote --tags git:// | ...

The location of the public repository is pretty much guaranteed to stay fixed, so I wouldn't really consider it brittle. The output of git-ls-remote will pretty definitely not change either.

The version number should be the last tag; you could grab it with something like this:

git ls-remote ... | tail -n 1 | sed 's@.*refs/tags/\(.*\)\^{}@\1@'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download