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

I’m writing a git-install.sh script:
http://gist.github.com/419201

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

  • Release notes from git log using bash awk
  • Formatting git log output with sed/awk/grep
  • How can I find all the merges that had conflicts in a Git repository?
  • Format git log output with sed, awk, or the like
  • Bash alias of an svn command piped to awk
  • Ignore empty results for xargs in Mac OS X
  • LSR_NUM=$(curl -silent http://git-scm.com/ | 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 http://git-scm.com/
      changes, the line above may stop
      working.

      PHP has a reliable URL for getting
      the latest release version:
      Is there a site which simply outputs the latest stable version numbers of php and mysql?

      Is there something like this for
      Git? This comes close: http://www.kernel.org/pub/software/scm/git/

  • Moving commits back to master
  • Git clone “fatal: I don't handle protocol 'ssh'”
  • Working with git on two computer (with github)
  • Failed to connect to repository : Error performing command: git.exe ls-remote -h https://github.com/szabbas/Sample-programs.git HEAD
  • git submodule update is slow. How can I debug why it's slow?
  • .gitignore - ignore file starting with ~
  • 5 Solutions collect form web for “How do I get Git's latest stable release version number?”

    I’d just do this:

    git ls-remote --tags git://git.kernel.org/pub/scm/git/git.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@'
    

    I use git-scm.com for this.

    latest_git_version=$(curl -s http://git-scm.com/ | grep "class='version'" | perl -pe 's/.*?([0-9\.]+)<.*/$1/')
    echo $latest_git_version 
    

    Very useful when you are on a new box and want to install latest stable git like so:

    cd /tmp
    wget http://git-core.googlecode.com/files/git-${latest_git_version}.tar.gz
    tar xzf git-${latest_git_version}.tar.gz
    cd git-${latest_git_version}
    ./configure && make && sudo make install
    

    Maybe this would also be a good fallback for kernel.org or vice versa.

    I generally just use the maint branch. It only gets commits that have been rigorously tested in other branches like pu or next. It is generally very stable and at any given time is actually likely to contain less bugs than the latest official release.

    I am using this on freebsd/bash:

    git ls-remote --tags https://github.com/user/testpro.git | tail -n 1 | sed 's/.*refs\/tags\///g'

    I use github.com and remove “-rc” versions due to kernel.org reponses unstably.

    curl -s https://github.com/git/git/tags | grep -P "/git/git/releases/tag/v\d" | grep -v rc | awk -F'[v\"]' '{print $3}' | head -1

    If you’d like to check the result in bash;

    GIT_INSTALL=$(curl -s https://github.com/git/git/tags | grep -P "/git/git/releases/tag/v\d" | grep -v rc  |  awk -F'[v\"]' '{print $3}' | head -1)
    
    if [[ "$GIT_INSTALL" =~ ^[0-9]*?\.[0-9]*?\.[0-9] ]]
    then
      echo GIT_INSTALL=$GIT_INSTALL
    else
      echo "Failed to get the latest stable git version. Quit." 
      exit
    fi
    
    Git Baby is a git and github fan, let's start git clone.