views:

29

answers:

2

I know how to list the remote branches

$ git branch -a

And I know how to find the head commit hash of my current branch

$ git rev-parse HEAD

But I'm not sure how to list all the head commit hashes for all the remote branches. This is close to what I want but what order are they in?

$ git rev-parse --remotes
4b9f7128e9e7fa7d72652ba49c90c37d0727123d
4ebab9616fac6896b7827e8502b4dc7c5aac6b5b
ea7a5fab4a757fb0826253acf1fe7d8c546c178e
...

Ideally, I'd like a list of branch-name commit-hash pairs or even a way to pass a remote branch name to git rev-parse HEAD

+1  A: 

Use either

git branch -r -v --no-abbrev

and ignore part with commit message or

git show-ref

and filter results starting with refs/remotes.

max
A: 

You can use git rev-parse for this. It can take anything which looks even remotely like a commit and returns the full SHA1 hash for that commit.

For example, to get the SHA1 of HEAD:

git rev-parse HEAD

To get the SHA1 of master:

git rev-parse master

To get the SHA1 of origin/trunk:

git rev-parse origin/trunk

To get the SHA1s of all remote heads (this is just one of many ways to do this, and certainly not the best one):

 git branch -r | cut -d' ' -f 3 | while read remote; do
   echo ${remote} `git rev-parse ${remote}`
done
Jörg W Mittag