1db79f97f5523cd2c76b5dfb8185a6d3b7a789d9

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

git: use `master` if it exists, otherwise use `main`

See https://github.com/ohmyzsh/ohmyzsh/pull/9049#issuecomment-654537347

Co-authored-by: Yufan You <ouuansteve@gmail.com>

Diff

 1diff --git a/plugins/git/README.md b/plugins/git/README.md
 2index b7f216813c45d0b2c8cb5e3231b0d74ad4b0f581..e809e1bcd2f5dee9468fdc7b3e10e70153554209 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 that branch exists. We do this via the
10-function `git_main_branch`.
11+that any aliases and functions that previously used `master`, will use `main` if `master` doesn't exist. We do this via
12+the function `git_main_branch`.
13 
14 ### Deprecated aliases
15 
16@@ -214,7 +214,7 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa
17 | current_branch         | Return the name of the current branch                                        |
18 | git_current_user_name  | Returns the `user.name` config value                                         |
19 | git_current_user_email | Returns the `user.email` config value                                        |
20-| git_main_branch        | Returns the name of the main branch: `main` if it exists, `master` otherwise |
21+| git_main_branch        | Returns the name of the main branch: `master` if it exists, `main` otherwise |
22 
23 ### Work in Progress (WIP)
24 
25diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
26index 5a9ccff5c12e36a6840085e6b82d2ec812192b91..6cae3dac258a722da641e5ee59844a6453e361cd 100644
27--- a/plugins/git/git.plugin.zsh
28+++ b/plugins/git/git.plugin.zsh
29@@ -27,10 +27,10 @@ function work_in_progress() {
30 
31 # Check if main exists and use instead of master
32 function git_main_branch() {
33-  if [[ -n "$(git branch --list main)" ]]; then
34-    echo main
35-  else
36+  if [[ -n "$(git branch --list master)" ]]; then
37     echo master
38+  else
39+    echo main
40   fi
41 }
42