1

I'm on a sort of frankendebian stretch/sid (not the best idea, I know; planning on reinstalling soon).

Tab completion works for git branch names in git repo directories:

:~/project $ git checkout <TAB><TAB>
Display all 200 possibilities? (y or n)

:~/project $ git checkout private-rl_<TAB><TAB>
private-rl_1219_misspelled_locale_zhtw   private-rl_1950_scheduler_offset         private-rl_bootstrap_rake_tasks
private-rl_1854_ldap_filter_reset        private-rl_bootstrap_rake_task

But some of the branches it shows don't exist anymore:

:~/project $ git branch
* develop
  private-rl_1219_misspelled_locale_zhtw
  stable

This also happens for deleted remote branches.

What's going on here? Does the git completion script keep a cache of old branches that can be flushed somehow? How can I stop these branches from accumulating in my tab-completion results?

  • Are you sure they are not tags? Autocompletion takes into account tags, and many other things. See top comments on github.com/git/git/blob/master/contrib/completion/… – Patrick Mevzek May 3 '18 at 13:24
  • I'm 100% sure they're not tags. I created and deleted those branches myself. Weird though — I just did $ sudo fd --hidden --no-ignore git-completion /, and didn't get any results. – Ryan Lue May 3 '18 at 14:04
  • Do git branch -a to see all branches. Remote branches may be taken into account also. – Patrick Mevzek May 3 '18 at 14:09
  • Thanks, it was references to deleted remotes (see answer below). – Ryan Lue May 3 '18 at 14:30
-1

git(1) comes with contributed files in git/contrib/completion/ in the source. The script for your shell handles completions.

  • I appreciate the sentiment, but the script as linked by @PatrickMevzek above is already over 3,000 lines long. If I had all day to read through git-completion.bash, well, I'd probably take my dogs for a hike instead anyway. – Ryan Lue May 3 '18 at 14:07
3

I figured it out, thanks to some gentle prodding from @PatrickMevzek:

The branches I was seeing were actually references to remote branches that had already been deleted. To quote the top answer from the SO thread linked above,

$ git remote prune origin

fixed it for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.