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.
Asked
Active
Viewed 1.1k times
6
Steven Hepting
- 271
1 Answers
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
ShockwaveNN
- 393