I'm currently trying, for fun, to build a package management system (similar to apt / yum / zypper, etc...) using the git revision system, and I' searching for a way to know what is the latest stable version of the current branch.

Example : the Linux kernel

I would like to know, from the 3.18 branch, what is the latest tag (currently "3.18.9"), and, if possible, the commit identification code (currently "d1034e83796a0433194f67c2a8c4abf0f6138b01").

How can I do it without having to downloading all the repository?

1 Answer 1


There might be a simpler variant, but the following will get you the commit SHA-1 of the last commit to the master branch:

git show -s origin/master

(assuming your remote is called origin in your local repository).

If you only want the commit,

git show -s origin/master | awk 'NR == 1 { print $2 }'

To make sure you're getting the latest information, you should git fetch beforehand. Referring to origin/master means this works regardless of the state of your local master, so you don't need to git pull.

You can't use git locally without cloning the repository you're interested in, but you can limit the amount of data copied by using --depth and --branch options to git clone; for example

git clone --branch linux-3.18.y --depth 5 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

to clone the last five history entries in the linux-3.18.y branch of the stable kernel tree. This is called a shallow clone and has a number of limitations; see the git clone documentation for details.

  • Is there a way to do it without having to fetch the repository?
    – Dremor
    Mar 16, 2015 at 10:42
  • Just drop the git fetch && part; that was just to ensure you're really getting the latest commit. Mar 16, 2015 at 10:43
  • What's kernel318 on your system? Mar 16, 2015 at 10:53
  • I'm still new at using git. I have created my current git repository with git init && git remote add -t v3.18 kernel318 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git. Probably not the good way, but it didn't show any error when I used it ^^"
    – Dremor
    Mar 16, 2015 at 10:56
  • OK, so that means you haven't yet fetched any information from the remote tree; therefore git can't give you any history or commit identifiers etc. Generally speaking when working from a remote repository you'd start by cloning it; see my updated answer for an example. Mar 16, 2015 at 11:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .