3

I'm using the bash completion script for git. However, there are situations where it doesn't work. Say I have a branch foo-branch, and a file foo-file. If I have changes in the file which I want to throw away, I'll often do:

git checkout fo<tab>

This completes immediately to foo-branch. Usually, if there are multiple completion options, I get a bell, and another tab will show me the options. Is there any way to get the completion to work like that in this case as well? Or does the git completion always take precedence over the file name completion?

Edit: I've waded through the bash man page and found -o plusdirs, which I added to the complete directive. This works; I'll have to try it for a while to see if it doesn't cause problems with commands that don't take a file name argument.

Erik Hesselink
  • 2,420
  • 21
  • 25
  • Shameless plug: I wrote git-number so that I don't have to write filenames for git arguments anymore: https://github.com/holygeek/git-number – holygeek Aug 26 '11 at 10:15

2 Answers2

2

To separate filename-completion from ref-completion add -- as a separator:

git checkout foo -- file.c

or

git checkout -- file.c

.

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
  • Thank you, that works. However, it would be nicer if I didn't have to remember to add the separator, because I'm going to keep forgetting it and complete to the branch again. – Erik Hesselink Aug 26 '11 at 09:14
  • As a human being, you should be able to adapt to a situation :-). OTOH, GIT and git-bash-completion are GPL, so adapt them if you can. – Patrick B. Aug 26 '11 at 09:18
0

It may seem simple, but I avoid problems like this by not making branch names that conflict.

Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94