<pre><code>git show -s --format=&quot;%H&quot; &lt;HEAD or Branch Name&gt;
</code></pre>
<p><code>-s</code> supressess the diff output</p>
<p><code>--format=&quot;%H&quot;</code> specifies that only the hash should be shown.</p>
<p>See <code>man git-show</code> for more details.</p>

CC BY-SA 4.0
2020-11-10T01:12:31.237Z
2020-11-10T01:12:31.237Z
Rystraum
<p>I have JenkinsFile where I'm trying to get the hash for my current branch. I saw this post: <a href="https://stackoverflow.com/questions/9110478/how-to-find-the-hash-of-branch-in-git">https://stackoverflow.com/questions/9110478/how-to-find-the-hash-of-branch-in-git</a></p>
<p>but when I tried to run <code>def BranchHash = sh &quot;git rev-parse ${BRANCH-NAME}</code> I got: <code>fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree</code></p>
<p>I'm looking for the branch hash, and not the last commit</p>

<git>
How to get branch hash using git command
arielma
# How to get branch hash using git command

(Asked by: username_0 on 2020-11-08)

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 "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

**Tags:** git


---

## 1 answers

### Answer by username_1 on 2020-11-10. Score: 2 | Accepted answer

git show -s --format="%H" 

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


---

