I’ve been asked this a few times and have had to do it lately a few times.

To get the SHA of the last commit from a specific branch, use git rev-parse

git rev-parse origin/master (remote branch)

or

git rev-parse master (local branch)