Skip to content

Instantly share code, notes, and snippets.

@thepaul
Created December 18, 2020 17:22
Show Gist options
  • Save thepaul/adc3e98f3b1c3d54e8fcdc2fd597cd38 to your computer and use it in GitHub Desktop.
Save thepaul/adc3e98f3b1c3d54e8fcdc2fd597cd38 to your computer and use it in GitHub Desktop.
Get the name of the remote HEAD (the default branch on that remote)
#!/bin/bash -e
REMOTE=${1:-origin}
ref=$(git rev-parse --symbolic-full-name "$REMOTE/HEAD" 2>/dev/null) || {
git remote set-head "$REMOTE" -a >/dev/null
ref=$(git rev-parse --symbolic-full-name "$REMOTE/HEAD")
}
echo "${ref#refs/remotes/$REMOTE/}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment