Skip to content

Instantly share code, notes, and snippets.

@tony-sol
Last active April 17, 2024 14:57
Show Gist options
  • Save tony-sol/00eb6393b1df1b70d90c07ddd937434f to your computer and use it in GitHub Desktop.
Save tony-sol/00eb6393b1df1b70d90c07ddd937434f to your computer and use it in GitHub Desktop.
git get-head command for fetch default branch name
#!/bin/zsh
set -e
git_get_head() {
(git symbolic-ref "refs/remotes/${@}/HEAD" --short || git remote show "${@}" ) 2>/dev/null | grep "${@}/\|HEAD branch" | sed -E "s#${@}/|HEAD branch:##" | sed 's# ##g'
}
git_get_head "${1}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment