Search code examples
gitgit-remote

Git: Find which commit is checked out on a remote


I have a local repo, and this repo has a remote. I want to know which commit (by SHA number) is checked out on the remote, assuming the remote is not a bare repository.

Clarification: I don't want anything to do with tracking branches or any other kind of branches on my local repository. In fact I want a method that works even if my local repository is a bare repository. Imagine that my remote is ssh://whatever/foo, so I want to get the equivalent of SSHing into the server whatever, doing cd /foo and git rev-parse HEAD.

I don't want to do the above example directly because I can't guarantee that I'll have SSH access to the remote. I want a method that works regardless of the type of remote

I want the response to be a SHA, not a branch name


Solution

  • git ls-remote origin HEAD
    

    (any repo reference will do for origin, you can used a url or a path)