user3678812
user3678812

Reputation: 457

Getting the last commit hash from a remote repo without cloning

I want to get the hash of last commit that has happened 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 hash.

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

Note:

Upvotes: 34

Views: 21532

Answers (3)

sTodorov
sTodorov

Reputation: 5461

One way would be the following:

  1. Initialize your local repo: git init

  2. Add your the remote to it: git remote add myRemote "https://myremoterepo"

  3. Fetch the repo and check the history for the last commit: git fetch remote

Alternatively, you could also go to the repo page on github (I assume from your tag) and check the commits tab. It will show you the latest commit and its sha.

Upvotes: -5

stevec
stevec

Reputation: 52758

Just a note in addition to @gturri's answer, that you can also use the name of the remote (as opposed to the url).

E.g. if you push with something like: git push heroku master, then you could use

git ls-remote heroku

This example assumes the name of your remote is 'heroku'.

You can replace 'heroku' above with whatever your remote is called.

Upvotes: -3

gturri
gturri

Reputation: 14629

$ git ls-remote https://github.com/gturri/dokuJClient.git 
2fb540fc8c7e9116791638393370a2fa0f079737    HEAD
2fb540fc8c7e9116791638393370a2fa0f079737    refs/heads/master

This command can be run from any directory.

If you only want the last sha1, eg to use it in a script, you could then do:

git ls-remote https://github.com/gturri/dokuJClient.git HEAD | awk '{ print $1}'

Upvotes: 80

Related Questions