4

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?

4
  • 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/… Commented May 3, 2018 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
    Commented May 3, 2018 at 14:04
  • Do git branch -a to see all branches. Remote branches may be taken into account also. Commented May 3, 2018 at 14:09
  • Thanks, it was references to deleted remotes (see answer below).
    – Ryan Lue
    Commented May 3, 2018 at 14:30

3 Answers 3

7

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.

0

Depending on your setup, there is another source of what might look like old or deleted branches - your git-completion may also be suggesting tags along with branches.

I was fooled by this recently - our CI/CD pipeline tags all our builds, and even though certain branches would be released and/or deleted years ago, the tags persisted. Cleaning up old tags on the remote was the solution here (there is a guide here.

-1

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

1
  • 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
    Commented May 3, 2018 at 14:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .