How to configure git bash command line completion?

前端 未结 12 1376
猫巷女王i
猫巷女王i 2020-11-28 18:50

E.g. on a fresh ubuntu machine, I\'ve just run sudo apt-get git, and there\'s no completion when typing e.g. git check[tab].

I didn\'t find

相关标签:
12条回答
  • 2020-11-28 19:43

    On Linux

    on most distributions, git completion script is installed into /etc/bash_completion.d/ (or /usr/share/bash-completion/completions/git) when you install git, no need to go to github. You just need to use it - add this line to your .bashrc:

    source /etc/bash_completion.d/git
    # or
    source /usr/share/bash-completion/completions/git
    

    In some versions of Ubuntu, git autocomplete may be broken by default, reinstalling by running this command should fix it:

    sudo apt-get install git-core bash-completion
    

    On Mac

    You can install git completion using Homebrew or MacPorts.

    Homebrew

    if $BASH_VERSION > 4: brew install bash-completion@2 (updated version) Pay special care which version of bash you have as MacOS default ships with 3.2.57(1)-release.

    add to .bash_profile:

      if [ -f /usr/local/share/bash-completion/bash_completion ]; then
        . /usr/local/share/bash-completion/bash_completion
      fi
    

    For older versions of bash: brew install bash-completion

    add to .bash_profile:

    [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
    

    MacPorts

    sudo port install git +bash_completion

    then add this to your .bash_profile:

    if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
    fi
    

    more info in this guide: Install Bash git completion

    Note that in all cases you need to create a new shell (open a new terminal tab/window) for changes to take effect.

    0 讨论(0)
  • 2020-11-28 19:43

    See https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

    You just need to source the completion script

    0 讨论(0)
  • 2020-11-28 19:43

    Arch Linux

    Source /usr/share/git/completion/git-completion.bash in one of the bash startup files.

    For example:

    # ~/.bashrc
    
    source /usr/share/git/completion/git-completion.bash
    

    You may be able to find the script in other locations like /usr/share/bash-completion/completions/git but these scripts did not work for me.

    0 讨论(0)
  • 2020-11-28 19:45

    on my ubuntu there is a file installed here:

    source /etc/bash_completion.d/git-prompt
    

    you can follow the links into the /usr/lib/git-core folder. You can find there an instruction, how to set up PS1 or use __git_ps1

    0 讨论(0)
  • 2020-11-28 19:45

    On Github in the Git project, They provide a bash file to autocomplete git commands.

    You should download it to home directory and you should force bash to run it. It is simply two steps and perfectly explained(step by step) in the following blog post.

    code-worrier blog: autocomplete-git/

    I have tested it on mac, it should work on other systems too. You can apply same approach to other operating systems.

    0 讨论(0)
  • 2020-11-28 19:50

    i had same issue, followed below steps:

    curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
    

    then add the following lines to your .bash_profile (generally under your home folder)

    if [ -f ~/.git-completion.bash ]; then
      . ~/.git-completion.bash
    fi
    

    source : http://code-worrier.com/blog/autocomplete-git/

    0 讨论(0)
提交回复
热议问题