Skip to content

Instantly share code, notes, and snippets.

@mjj2000
Last active November 13, 2024 08:25
Show Gist options
  • Save mjj2000/3ee188cc155c26a118b06116ad0ebd1d to your computer and use it in GitHub Desktop.
Save mjj2000/3ee188cc155c26a118b06116ad0ebd1d to your computer and use it in GitHub Desktop.
[GIT] Get tag of current branch(that is HEAD) or fallback to short commit hash(7 digits) by single shell command
git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD
@dbadrian
Copy link

Brilliant. Very useful!

@RaymsDev
Copy link

Exactly what I needed !

@ChristophP
Copy link

Thanks :-)

@mogaika
Copy link

mogaika commented Jul 5, 2022

git describe --tags --always

@uli-f
Copy link

uli-f commented Dec 12, 2023

Thanks, works perfectly.

@infogulch
Copy link

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment