Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git tab completion stopped working on remote branches

I've updated git to its latest version (2.29.0) and I'm using ZSH 5.8.

I used to switch between branches with git checkout remote_br<tab> to quickly switch between branches, even if the branch is only a remote one atm. I've seen git has made a lot of changes regarding switch/checkout recently, the thing is my autocompletion on remote branches doesn't work anymore (with checkout or switch).

I've tried to add the latest version of contrib/completion/git-completion.zsh to my zsh, but I still have my issue. Am I missing something here ?

like image 476
RobinFrcd Avatar asked Sep 07 '20 10:09

RobinFrcd


People also ask

How do I set up tab completion for Git branches?

Tab completion is a nice feature of many shells that allows you to complete a word by hitting tab. In this case, we want to be able to use tab completion for things like branches and tags in git. Fortunately, setting it up is pretty simple. First, open a shell and navigate to your home directory because that's where the script will reside.

How do I set a remote branch in Git?

If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you’re tracking, you can use the -u or --set-upstream-to option to git branch to explicitly set it at any time. $ git branch -u origin/serverfix Branch serverfix set up to track remote branch serverfix from origin.

How does git pull work with tracking branches?

If you have a tracking branch set up as demonstrated in the last section, either by explicitly setting it or by having it created for you by the clone or checkout commands, git pull will look up what server and branch your current branch is tracking, fetch from that server and then try to merge in that remote branch.

What happens when you clone a git branch?

If you clone from this, Git’s clone command automatically names it origin for you, pulls down all its data, creates a pointer to where its master branch is, and names it origin/master locally. Git also gives you your own local master branch starting at the same place as origin’s master branch, so you have something to work from.


2 Answers

I've been looking into this for the last few hours and have identified the regression.

The regression occurs in 6880779.

To temporarily resolve this: replace your git-completion.bash file (mine's located at /usr/local/share/zsh/site-functions/git-completion.bash) with https://github.com/git/git/blob/688077910bdfbd502cb59c9c48a2af2c97d8b67b~1/contrib/completion/git-completion.bash

To really resolve this, upvote my git PR and help get it merged! (https://github.com/git/git/pull/902)

like image 133
Max Coplan Avatar answered Oct 17 '22 11:10

Max Coplan


Try the following patch:

--- a/git-completion.zsh
+++ b/git-completion.zsh
@@ -97,6 +97,11 @@ __gitcomp_direct ()
        compadd -Q -S '' -- ${(f)1} && _ret=0
 }
 
+__gitcomp_direct_append ()
+{
+       __gitcomp_direct "$@"
+}
+
 __gitcomp_nl ()
 {
        emulate -L zsh

In general it's better to report bugs to the git mailing list, however, I'm the maintainer of the zsh code, which is more up to date in my fork: git-completion.

like image 37
FelipeC Avatar answered Oct 17 '22 13:10

FelipeC