Git Auto-complete not working in bash

14,103

Use this script for Ubuntu:

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

Read the documentation on how to set it up:

 To use these routines:

    1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
    2) Add the following line to your .bashrc/.zshrc:
       source ~/.git-completion.bash
    3) Consider changing your PS1 to also show the current branch,
       see git-prompt.sh for details.

A shorter solution:

# install the bash-completion vai apg-get 
sudo apt-get install git bash-completion
Share:
14,103
MysticCode
Author by

MysticCode

Updated on July 27, 2022

Comments

  • MysticCode
    MysticCode almost 2 years

    I recently installed git. I am using Ubuntu 14.04. However the autocomplete feature is not working.

    Whenever I type git i then TAB it should be git init but it doesn't happen so. I have tried everything mentioned in this page, still no success.

    Whenever I do git in then TAB it seems like git is pinging unknown host. Below is the screenshot:

    enter image description here

    How do I resolve this?

  • MysticCode
    MysticCode about 8 years
    I did step 1 and 2 still no success.
  • CodeWizard
    CodeWizard about 8 years
    try the updated apt-get option and update me if it working or not
  • MysticCode
    MysticCode about 8 years
    That also did not work out. It says bash-completion is already the newest version
  • CodeWizard
    CodeWizard about 8 years
    Ok, now try to source it: source ~/.git-completion.bash. if still not working try to set the chmod 664/755 on this file
  • MysticCode
    MysticCode about 8 years
    I dont know but the problem still persists. I also tried changing the permissions. I also have sourced .git-completion.bash in my .bashrc. .git-completion.bash also exists in my home directory. I don't know what the problem is
  • MysticCode
    MysticCode about 8 years
    Finally resolved the problem. The problem seemed to be with my .bashrc file ..i replaced ~/.bashrc with /etc/skel/.bashrc now its working
  • Asalle
    Asalle about 7 years
    The shorter solution did not work for me, but the former one did.
  • Martin Lyne
    Martin Lyne about 6 years
    Long oslution didn't work for me on Xenial, but shorter one did 👌
  • Erasmus Cedernaes
    Erasmus Cedernaes almost 6 years
    @MysticCode The /etc/skel/.bashrc was the solution for me as well. You should add it as an answer and mark it as the solution.
  • MountainDrew
    MountainDrew almost 4 years
    The "shorter solution" of this answer worked for me, though I had to close my terminal and open a new terminal in order for it to take effect.
  • J.Ko
    J.Ko about 3 years
    Just running the second step worked for me.