feat(git): guess main branch name also from remotes (#10158)
Co-authored-by: Marc Cornellà <hello@mcornella.com>
Diff
1diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
2index f0d9aaedc8f8bd4682152c0dbff87d268c6e42e8..2985ba0243cc912b1b2919d8475deb76e5876efe 100644
3--- a/plugins/git/git.plugin.zsh
4+++ b/plugins/git/git.plugin.zsh
5@@ -32,10 +32,10 @@ function work_in_progress() {
6 # Check if main exists and use instead of master
7 function git_main_branch() {
8 command git rev-parse --git-dir &>/dev/null || return
9- local branch
10- for branch in main trunk; do
11- if command git show-ref -q --verify refs/heads/$branch; then
12- echo $branch
13+ local ref
14+ for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk}; do
15+ if command git show-ref -q --verify $ref; then
16+ echo ${ref:t}
17 return
18 fi
19 done