Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
55a98fc0
Commit
55a98fc0
authored
Jul 11, 2020
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git: better algorithm to decide what's the main branch
Fixes #9103 Co-authored-by:
Yufan You
<
ouuansteve@gmail.com
>
parent
9cdc2764
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
+22
-5
git.plugin.zsh
plugins/git/git.plugin.zsh
+22
-5
No files found.
plugins/git/git.plugin.zsh
View file @
55a98fc0
...
...
@@ -25,13 +25,30 @@ function work_in_progress() {
fi
}
# Check if main exists and use instead of master
# Get the default 'main' branch
# Marc(2020-07-11): I hope to be able to remove this someday
function
git_main_branch
()
{
if
[[
-n
"
$(
git branch
--list
master
)
"
]]
;
then
echo
master
else
echo
main
# Get default branch from the origin remote
local
branch
branch
=
"
${$(
command
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null
)
#refs/remotes/origin/
}
"
if
[[
-n
"
$branch
"
]]
;
then
echo
"
$branch
"
return
fi
# Look up list of local branches and return the first one that exists
local
-a
branches
branches
=(
${
(@f)
"
$(
command
git
for
-each-ref
--format
=
'%(refname:short)'
refs/heads 2>/dev/null
)
"
}
)
for
branch
in
master main
;
do
if
((
${
branches
[(Ie)
$branch
]
}
))
;
then
echo
"
$branch
"
return
fi
done
echo
master
return
1
}
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment