2

I want to get the last commit date in a remote repo without cloning it. Is there a way to do this ? I found several methods but for all of them to work, I need to clone the repo first and then issue the commands to get the last commit date.

Is there a way I can get the last commit date from a remote git without cloning it ?

Jhansi
  • 21
  • 1
  • 1
    That depends on the git server you're connecting to. Azure DevOps has a REST API you could leverage for example, GitHub as well... These APIs are platform specific though. – jessehouwing May 27 '21 at 10:52

1 Answers1

3

If it's remote, it's on another server. This means you will need to connect to it somehow, whatever the solution. A usual solution is to just SSH:

ssh remote.server /bin/bash -c 'cd /path/to/remote/repo && git log --all -1 --format=%cd'

Some usual production UIs have rest APIs you can use etc. For Github for example, you can fetch the latest commit object with

https://api.github.com/repos/<user name>/<repo>/commits/<brancH>

(This is based on How can I get last commit from GitHub API) and parse the Json (or Yaml I don't know what they have now, Json seems enough) - under auther and commiter there are dates. If you don't know which branch has the latest commit you have to check them all.

kabanus
  • 24,623
  • 6
  • 41
  • 74