6

I would like to be able to ask Git "what is the default branch name for this repository?" and I would expect either main or master as the result. I've search git config but haven't been able to find a/the relevant option.

1 Answers1

10

This simple snippet should work:

git remote show origin | sed -n '/HEAD branch/s/.*: //p'

Replace origin with name of your remote if it's not default