How can I set up autocompletion for Git commands?

后端 未结 9 1405
挽巷
挽巷 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:14

    For Manjaro and other Arch-based distros. I know it's about debian, but most things are the same but sometimes not. Whatever OS you use you'll end up here.

    In your ~/.bashrc add:

    source /usr/share/git/completion/git-completion.bash
    

    And then in terminal

    $ source ~/.bashrc
    
    0 讨论(0)
  • 2021-01-31 08:17

    Use Notepad++ to edit your ~/.bashrc file. Put the line at the bottom of the script with a # at the beginning of the line. Save the file. For example: # source C:\cygwin64/etc/bash_completion.d/git

    Don't forget to put the entire file path after 'source' and in front of '/etc/' For example, my cygwin64 folder which contains the 'etc' folder is in my c drive so my file path is c:\cygwin64/etc therefore the line I included in my bashrc file is:

    # source c:\cygwin64/etc/bash_completion.d/git
    

    Save bashrc file. Open Cygwin Terminal ... Boom! It's go time. I then entered the following command and it worked. git clone git:\/\/github.com/magnumripper/JohnTheRipper -b bleeding-jumbo JtR-Bleeding

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

    You need to source /etc/bash_completion.d/git to enable git auto-completion.

    In my .bashrc it's done with:

    for file in /etc/bash_completion.d/* ; do
        source "$file"
    done
    
    0 讨论(0)
  • 2021-01-31 08:26

    You need to install this package if missing. And then logout and login.

    apt-get install bash-completion
    
    0 讨论(0)
  • 2021-01-31 08:27

    Put the following lines in your ~/.bashrc

    if [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
    

    The script/program /etc/bash_completion already includes the scripts in /etc/bash_completion.d and also defines some functions needed by the included scripts.

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

    At times git auto-complete disappears because you accidentally deleted your ~/.bashrc file. Check if the bashrc file is there in your home directory. If not, you can always copy it from:

    /etc/skel/.bashrc
    
    0 讨论(0)
提交回复
热议问题