3

Is it possible to remotely retrieve the latest commit hash of a Github repo without cloning it locally? I'm referring to something like the following you see at the top of all the repos in Github:

Github Latest Commit

Based on some older questions it seems that this may not be possible with git directly (unless there's a new feature that enables it), so the right answer might involve using the Github API (turns out Github API won't work for my use case since I'll have to use a different set of credentials then the private key git uses).

Community
  • 1
  • 1
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
  • Possible duplicate of [How to get the last commit ID of a remote repo using curl-like command?](http://stackoverflow.com/questions/19176359/how-to-get-the-last-commit-id-of-a-remote-repo-using-curl-like-command) – Alexis Tyler Aug 29 '16 at 01:34
  • Possible duplicate of [Getting the last commit hash from a remote repo without cloning](https://stackoverflow.com/questions/24750215/getting-the-last-commit-hash-from-a-remote-repo-without-cloning) – Gregor Oct 19 '17 at 12:48

1 Answers1

8

Found the answer here thanks to @jszakmeister:

git ls-remote $URL HEAD

For my private repo, I had to use the following syntax instead of the URL:

git ls-remote git@github.com:ORG/PROJECT.git HEAD
Community
  • 1
  • 1
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197