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
c99f3c50
Commit
c99f3c50
authored
Jul 15, 2020
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git: go back to previous main branch detection logic
Fixes #9114
parent
ff7618cf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
30 deletions
+14
-30
README.md
plugins/git/README.md
+9
-9
git.plugin.zsh
plugins/git/git.plugin.zsh
+5
-21
No files found.
plugins/git/README.md
View file @
c99f3c50
...
...
@@ -183,8 +183,8 @@ plugins=(... git)
Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin favors using
a branch name other than
`master`
. In this case, we favor the shorter, neutral and descriptive term
`main`
. This means
that any aliases and functions that previously used
`master`
, will use
`main`
if
`master`
doesn't exist. We do this via
the
function
`git_main_branch`
.
that any aliases and functions that previously used
`master`
, will use
`main`
if
that branch exists. We do this via the
function
`git_main_branch`
.
### Deprecated aliases
...
...
@@ -209,12 +209,12 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa
### Current
| Command | Description |
|:-----------------------|:-----------------------------------------------------------------------------
----------
|
|:-----------------------|:-----------------------------------------------------------------------------|
|
`grename <old> <new>`
| Rename
`old`
branch to
`new`
, including in origin remote |
| current_branch | Return the name of the current branch |
| git_current_user_name | Returns the
`user.name`
config value |
| git_current_user_email | Returns the
`user.email`
config value |
| git_main_branch | Returns the name of the main branch:
from origin or from local branches, else 'master'
|
| git_main_branch | Returns the name of the main branch:
`main`
if it exists,
`master`
otherwise
|
### Work in Progress (WIP)
...
...
plugins/git/git.plugin.zsh
View file @
c99f3c50
...
...
@@ -25,29 +25,13 @@ function work_in_progress() {
fi
}
#
Get the default 'main' branch: from origin, from local branches, or else just 'master'
#
Check if main exists and use instead of master
function
git_main_branch
()
{
# 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
if
[[
-n
"
$(
git branch
--list
main
)
"
]]
;
then
echo
main
else
echo
master
return
1
fi
}
#
...
...
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