Does anyone know how to get the latest SHA of a given branch from outside a git repository?
If you are inside a git repository, you can do:
git log origin/branch_X | head -1
If you want to check SHA-1 of given branch in remote repository, then your answer is correct:
$ git ls-remote <URL>
However if you are on the same filesystem simpler solution (not requiring to extract SHA-1 from output) would be simply:
$ git --git-dir=/path/to/repo/.git rev-parse origin/branch_X
See git(1) manpage for description of '