After thorough research, it turns out that completion of git checkout
under ZSH is not fulfilled by oh-my-zsh, but from the _git
function provided with the shell facilities.
As stated in the comments, I couldn't reproduce the issue you experienced. Everything seems to work as expected. Nevertheless…
Check out the following file:
/usr/share/zsh/<5.x>/functions/_git
My local zsh version is 5.2. Around row 450, you can see:
case $state in
(branch-or-tree-ish-or-file)
# TODO: Something about *:: brings us here when we complete at "-". I
# guess that this makes sense in a way, as we might want to treat it as
# an argument, but I can't find anything in the documentation about this
# behavior.
[[ $line[CURRENT] = -* ]] && return
if (( CURRENT == 1 )) && [[ -z $opt_args[(I)--] ]]; then
# TODO: Allow A...B
local branch_arg='' \
remote_branch_noprefix_arg='remote branches::__git_remote_branch_names_noprefix' \
tree_ish_arg='tree-ishs::__git_tree_ishs' \
file_arg='modified-files::__git_modified_files'
if [[ -n ${opt_args[(I)-b|-B|--orphan|--detach]} ]]; then
remote_branch_noprefix_arg=
file_arg=
elif [[ -n $opt_args[(I)--track] ]]; then
branch_arg='remote-branches::__git_remote_branch_names'
remote_branch_noprefix_arg=
tree_ish_arg=
file_arg=
elif [[ -n ${opt_args[(I)--ours|--theirs|-m|--conflict|--patch]} ]]; then
remote_branch_noprefix_arg=
fi
_alternative \
$branch_arg \
$remote_branch_noprefix_arg \
$tree_ish_arg \
$file_arg && ret=0
Removing one of the arrays passed to _alternative
changes what's suggested to you when completing a branch name after git checkout
. In particular, removing $remote_branch_noprefix_arg
brings back remote branch names prefixed with origin
or their respective remote repository name.
Therefore, upgrading your shell or downgrading to a former version may be a good idea.
Some details yet:
- I saw you've edited your original post and
git push
have good reasons to work slightly differently than git checkout
;
- The homolog local branch of a remote one may not forcibly exists:
feature
is different from origin/feature
, even when the former one, when it exists, is generally configured to track the latter ;
- By default, if the local branch doesn't exist yet and when no explicit options are passed aside, checking out
feature
will create an eponym local branch configured to track the remote one, then switch to it, while checking out origin/feature
will put you in detached mode, allowing to browse this remote branch but directly commit on top of it.