How can I set up autocompletion for Git commands?

后端 未结 9 1406
挽巷
挽巷 2021-01-31 07:37

I have Git (version 1.7.2.5) bash compeletion working on my Debian squeeze (6.0). Git was installed with aptitude and I am using standard debian\'s bash, which supp

相关标签:
9条回答
  • 2021-01-31 08:35

    The shortest way to activate the bash auto-completion for Git on Debian is to add

    source /etc/bash_completion.d/git
    

    to the ~/.bashrc (and restart the terminal).

    See also here: "Pro Git" -> 2.7 Git Basics - Tips and Tricks -> Auto-Completion.

    0 讨论(0)
  • 2021-01-31 08:37

    For Ubuntu/Debian

    Install Git and bash-completion by the following command:

    sudo apt-get install git bash-completion
    

    I don't think you need to do anything else.

    0 讨论(0)
  • 2021-01-31 08:40

    Recent versions of Ubuntu (observed on 20.04) seem to have split completions into multiple paths. For Ubuntu 20.04, I had to add the following to my .bashrc (taken from the default bashrc found in /etc/bash.bashrc):

    if ! shopt -oq posix; then
      if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
      elif [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
      fi
    fi
    
    0 讨论(0)
提交回复
热议问题