Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

How to configure git bash command line completion?

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 anything on http://git-scm.com/docs, but IIRC completion is included in the git package these days and I just need the right entry in my bashrc.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

#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:

  [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...