Diff
1diff --git a/plugins/git/README.md b/plugins/git/README.md
2index b92d0bf028508dee1582a75f3c5d2861db0fdbe5..b7f216813c45d0b2c8cb5e3231b0d74ad4b0f581 100644
3--- a/plugins/git/README.md
4+++ b/plugins/git/README.md
5@@ -183,8 +183,8 @@ plugins=(... git)
6
7 Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin favors using
8 a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive term `main`. This means
9-that any aliases and functions that previously used `master`, will use `main` if `master` doesn't exist. We do this via
10-the function `git_main_branch`.
11+that any aliases and functions that previously used `master`, will use `main` if that branch exists. We do this via the
12+function `git_main_branch`.
13
14 ### Deprecated aliases
15
16@@ -208,13 +208,13 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa
17
18 ### Current
19
20-| Command | Description |
21-|:-----------------------|:---------------------------------------------------------------------------------------|
22-| `grename <old> <new>` | Rename `old` branch to `new`, including in origin remote |
23-| current_branch | Return the name of the current branch |
24-| git_current_user_name | Returns the `user.name` config value |
25-| git_current_user_email | Returns the `user.email` config value |
26-| git_main_branch | Returns the name of the main branch: from origin or from local branches, else 'master' |
27+| Command | Description |
28+|:-----------------------|:-----------------------------------------------------------------------------|
29+| `grename <old> <new>` | Rename `old` branch to `new`, including in origin remote |
30+| current_branch | Return the name of the current branch |
31+| git_current_user_name | Returns the `user.name` config value |
32+| git_current_user_email | Returns the `user.email` config value |
33+| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise |
34
35 ### Work in Progress (WIP)
36
37diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
38index 8f8edcd23fec11a11a87aa9898f8a04d47cc6aff..5a9ccff5c12e36a6840085e6b82d2ec812192b91 100644
39--- a/plugins/git/git.plugin.zsh
40+++ b/plugins/git/git.plugin.zsh
41@@ -25,29 +25,13 @@ function work_in_progress() {
42 fi
43 }
44
45-# Get the default 'main' branch: from origin, from local branches, or else just 'master'
46+# Check if main exists and use instead of master
47 function git_main_branch() {
48- # Get default branch from the origin remote
49- local branch
50- branch="${$(command git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)#refs/remotes/origin/}"
51-
52- if [[ -n "$branch" ]]; then
53- echo "$branch"
54- return
55+ if [[ -n "$(git branch --list main)" ]]; then
56+ echo main
57+ else
58+ echo master
59 fi
60-
61- # Look up list of local branches and return the first one that exists
62- local -a branches
63- branches=(${(@f)"$(command git for-each-ref --format='%(refname:short)' refs/heads 2>/dev/null)"})
64- for branch in master main; do
65- if (( ${branches[(Ie)$branch]} )); then
66- echo "$branch"
67- return
68- fi
69- done
70-
71- echo master
72- return 1
73 }
74
75 #