Disable auto-completion of remote branches in Git Bash?

后端 未结 9 1497
广开言路
广开言路 2020-11-30 01:59

I\'m working on a fairly large git repo with a couple of thousand (remote) branches. I am used to using auto-completion (using [TAB]) in the console (Git Bash in that case),

9条回答
  •  清歌不尽
    2020-11-30 02:20

    If you installed git-completion via homebrew, it's located here: /usr/local/etc/bash_completion.d/git-completion.bash

    Following erik.weathers' answer above, I made the following change so autocompletion can work for both local and remote based on the current prefix. By default, it'll only search local, but if I specify origin/… it'll know I want to search remote branches too.

    In the _git_checkout () method, change

        __gitcomp_nl "$(__git_refs '' $track)"
    

    to:

        # only search local branches instead of remote branches if origin isn't specified
        if [[ $cur == "origin/"* ]]; then
            __gitcomp_nl "$(__git_refs '' $track)"
        else
            __gitcomp_nl "$(__git_heads '' $track)"
        fi
    

    Of course, you can change origin to something else or you can have it search through through a list of remote prefixes if you have more than 1.

提交回复
热议问题