How to configure git bash command line termination?

eg. on a new ubuntu machine, I just ran sudo apt-get git and there is no completion on input, for example. git check[tab] .

I didn't find anything at http://git-scm.com/docs , but IIRC termination is included in the git package these days, and I just need the correct entry in my bashrc.

+88
git bash
Sep 13 '12 at 3:25
source share
10 answers

In Linux

on most distributions, the git completion script is installed in /etc/bash_completion.d/ (or /usr/share/bash-completion/completions/git ) when installing git, there is no need to switch 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 

On some versions of Ubuntu, git autocomplete may be broken by default, reinstalling with this command should fix this:

 sudo apt-get install git-core bash-completion 

On mac

You can install git complete using Homebrew or MacPorts.

Homebrew

if $BASH_VERSION > 4: brew install bash-completion@2 $BASH_VERSION brew install bash-completion@2 (updated version) Pay particular attention to what version of bash you have as MacOS with 3.2.57 by default (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 information in this guide: Install Bash Git Completion

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

+140
Sep 19 '13 at 15:16
source share

I had the same issue as below:

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

then add the following lines to .bash_profile (usually in your home folder)

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

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

+50
Nov 09 '13 at 13:13
source share

Most of the instructions you see will tell you to download

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

and the source that is in your bash startup script is .bashrc .

But there is a problem with this because it refers to the master branch, which is the latest version of git-completion.bash . The problem is that sometimes it breaks because it is not compatible with the version of git that you installed.

In fact, this will now break, because the master branch of git-completion.bash creation.bash has new features that require git v2.18, which no package manager or installer has yet to upgrade to. You will get unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config errors unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config

Therefore, the safest solution is to reference the version / tag that matches the git you installed. For example:

https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash

Please note that it has v2.17. in the URL instead of master . And then, of course, make sure the source of this is in the bash startup script.

+28
Jun 19 '18 at 1:26
source share
+15
Sep 13 '12 at 3:30
source share

Ubuntu 14.10

Install git-core and bash-completion

 sudo apt-get install -y git-core bash-completion 
  • For current session use

     source /usr/share/bash-completion/completions/git 
  • So that it always turns on for all sessions

     echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc 
+14
May 11 '16 at 8:57 a.m.
source share

on my ubuntu there is a file installed here:

 source /etc/bash_completion.d/git-prompt 

you can follow the links in the /usr/lib/git-core folder. You can find instructions there on how to configure PS1 or use __git_ps1

+2
Jul 05 '14 at 17:09
source share

May be useful to someone: -

After downloading .git-completion.bash from the following link

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

and trying to use the __git_ps1 function, I was getting an error like ...

  -bash: __git_ps1: command not found 

Apparently we need to load the scripts separately from master for this command to work, since __git_ps1 is defined in git -prompt.sh. Similar to loading .git-completion.bash, get git -prompt.sh:

 curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git 

and then add the following to your .bash_profile

 source ~/.bash_git if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash export PS1='\W$(__git_ps1 "[%s]")>' fi 

source ~ / .bash.git will execute the downloaded file and

Team

export PS1='\W$(__git_ps1 "[%s]") will add the name of the statement branch after the current working directory (if it is a git repository).

So it will look like this: -

dir_Name[branch_name] where dir_Name is the name of the working directory and panel_name is the name of the branch you are currently working on.

Please note: __git_ps1 is case sensitive.

+2
Aug 02 '16 at 6:51
source share

Just do it in your ~/.bashrc :

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

Other answers tell you about installing bash-completion , you do not need to do this, but if you do, then there is no need to directly get the completion. You do one or the other, not both.

A more general solution is to request a system location in accordance with the recommendations of the bash completion project:

 source "$(pkg-config --variable=completionsdir bash-completion)"/git 
0
Jun 25 '19 at 14:35
source share

Ubuntu

There is a beautiful answer here. Worked for me on Ubuntu 16.04

Window

Git Bash is an auto-complete tool. Not sure if this is part of the standard distribution, so you can find this link . By the way, Git Bash allows you to use Linux shell commands to work with windows, which is great for people who have experience in the GNU / Linux environment.

-one
Feb 01 '17 at 17:33
source share

On Github in a Git project, they provide a bash file to autocomplete Git commands.

You must load it into your home directory, and you must force bash to start it. These are just two steps and beautifully explained (step by step) in the next blog post.

code-worrier blog: autocomplete- git /

I tested it on mac, it should work on other systems as well. You can apply the same approach to other operating systems.

-one
Aug 29 '17 at 19:52 on
source share



All Articles