Copy latest Git commit hash


TL;DR: copy latest Git commit hash:

git show --oneline | head -1 | awk '{ print $1 }' | pbcopy

git show

git show the object at HEAD:

git show --oneline

Extract the first line with head:

head -1

Print the first field with awk:

awk '{ print $1 }'

Copy result to clipboard with pbcopy:

pbcopy

Putting it together with pipe:

git show --oneline | head -1 | awk '{ print $1 }' | pbcopy

git log

Copy the latest commit sha with git log:

git log --oneline | head -1 | awk '{ print $1 }' | pbcopy


If you enjoyed this post, please consider supporting this site!