How to get branch hash using git command I have JenkinsFile where I'm trying to get the hash for my current branch. I saw this post: https://stackoverflow.com/questions/9110478/how-to-find-the-hash-of-branch-in-git
but when I tried to run def BranchHash = sh &quot;git rev-parse ${BRANCH-NAME} I got: fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree
I'm looking for the branch hash, and not the last commit
git show -s --format=&quot;%H&quot; &lt;HEAD or Branch Name&gt;

-s supressess the diff output
--format=&quot;%H&quot; specifies that only the hash should be shown.
See man git-show for more details.