Skip to content

Instantly share code, notes, and snippets.

@taiki-e
Last active November 8, 2020 20:40
Show Gist options
  • Save taiki-e/5817b637930e65aacef2c6b73a3d3865 to your computer and use it in GitHub Desktop.
Save taiki-e/5817b637930e65aacef2c6b73a3d3865 to your computer and use it in GitHub Desktop.
Getting the default branch of a remote repository
# Gets the default branch of a remote repository.
#
# Example: git fetch --prune upstream && && git merge "upstream/$(default_branch upstream)"
function default_branch() {
git remote show "${1:-origin}" | grep 'HEAD branch' | sed 's/ *HEAD branch: //'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment