Git – How to find the hash of branch in Git


Given a local / remote branch name, how could I get the hash of the commit that this branch points to?

Best Solution

The command git rev-parse is your friend, e.g.:

$ git rev-parse development

... or for a remote-tracking branch:

$ git rev-parse origin/master

This command is generally very useful, since it can parse any of the ways of specifying branch names in git, such as:

git rev-parse master~3
git rev-parse HEAD@{2.days.ago}

... etc.