Git command to display HEAD commit id?


What command can I use to print out the commit id of HEAD?

This is what I'm doing by hand:

$ cat .git/HEAD
ref: refs/heads/v3.3
$ cat .git/refs/heads/v3.3

But I need a script that can reliably pipe the output of some command to a text file such that the text file contains exactly the commit id of HEAD (nothing more or less, and not just a ref). Can anyone help?


Use the command:

git rev-parse HEAD

For the short version:

git rev-parse --short HEAD

How can I see which Git branches are tracking which remote / upstream branch?

How do I check out a remote Git branch?