Skip to content

Instantly share code, notes, and snippets.

@JunaidQadirB
Last active June 16, 2020 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JunaidQadirB/5f67918e64dfe0357fc3dcee5df85730 to your computer and use it in GitHub Desktop.
Save JunaidQadirB/5f67918e64dfe0357fc3dcee5df85730 to your computer and use it in GitHub Desktop.
This shell script gives you the ability to get your git the version as well as the commit hash pretty easily, via two handy utility functions
#!/bin/bash
#Get Version
version() {
git ls-remote --tags $1 | awk -F/ '{ print $3 }' | tail -n1
}
# Get commit hash
hash() {
git ls-remote --tags $1 | awk -F/ '{ print substr($1,0,7) }' | tail -n1
}
case $1 in
version)
"$@"
exit
;;
commit)
"$@"
exit
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment