8

I think this may be a duplicate, but I can't find a straight answer to my current problem.

I'm trying to get my macosx git autocomplete to work similar to the git autocomplete I have on my linux box at work. I found some instructions that led me to install https://github.com/git/git/tree/master/contrib/completion (i'm using the .bash version). Everything works great, the only catch is that now the autocomplete shows branches that are already deleted.

Does anyone have an alternate script/method, or even just instruction on how to edit the current script to avoid showing all of my branches, and just the current local branches that are available.

thank you, Brodie

[edit]

I figured an example was in order, to help make the question clearer.

#result of git branch is as expected
$ git branch
 *master
  somefeature
  someotherfeature

#now I delete one of my feature branches
$ git branch -D someotherfeature
$ git branch
 *master
  somefeature
  #the branch someotherfeature is gone, as expected

#however when I attempt an autocomplete, like with git checkout, I get everything remote branches, local branches, and previously deeted branches.
$ git checkout <tab><tab>
  master    somefeature    someotherfeature    remote/origin/master    remote/origin/remotebranch 

I'd like to have it just show my local branches like it does on my linux box

# i.e. given 2 local branches `master` and `somefeature` autocomplete would work as follows
$ git checkout <tab><tab>
  master    somefeature
Brodie
  • 8,399
  • 8
  • 35
  • 55
  • Are you saying that you get autocompletion for branches that are not listed by the `git branch` command (run it without any arguments) – janos May 09 '14 at 17:17
  • yes I get all local and remote branches. I also get all branches I've ever created locally, including the ones I've deleted [git branch -D] – Brodie May 09 '14 at 19:27
  • 1
    if the `git branch` command shows you those branches, then they were NOT deleted. Your question and situation is not very clear. – janos May 09 '14 at 19:29
  • So what exactly is the output of `git branch`? Also, are you using the version of git that ships with OS X, or are you using whatever gets installed with Homebrew? –  May 10 '14 at 00:16
  • I'm using the git that came with the machine (to be honest, not sure what the install was as it is a company machine). @janos git branch does not show those branches, however the autocomplete does. So the result of git branch is what I'd expect (all local branches). Whereas, when I autocomplete (double tab) I get all remote branches, and all local branches (included branches that were previously deleted). – Brodie May 11 '14 at 19:45
  • @Cupcake and janos -- i've updated with an example of what is the output of git branch and git autocomplete and what i'd like to see autocomplete do. – Brodie May 11 '14 at 19:50
  • Autocomplete is a *shell* feature. Tell us what shell you are using. – bmargulies May 11 '14 at 19:50
  • I am using bash as my shell – Brodie May 11 '14 at 19:51
  • Maybe it's some kind of bug? I don't know `:/` –  May 11 '14 at 20:21

1 Answers1

6

In my version of git-completion.bash I can do the following to prevent these deleted branches displaying as part of completion:

export GIT_COMPLETION_CHECKOUT_NO_GUESS=1

I found it mentioned in the file (homebrew - /usr/local/Cellar/git/2.19.2/share/zsh/site-functions/git-completion.bash) and also in the SO post Disable auto-completion of remote branches in Git Bash?.

HankCa
  • 9,129
  • 8
  • 62
  • 83