👋

Configure git completion

2022/06/10に公開

After creating a .zsh/ directory, download the following two files and save them there.

git-completion.bash
git-completion.zsh

from git/contrib/completion on GitHub

Even zsh users need to install the git-completion.bash, whereas the git-completion.zsh needs to be saved with the filename _git. See the comment in the file for details.

mkdir ~/.zsh
cd ~/.zsh
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh

After downloading the above files, add the following script to ~/.zshrc.

## Git completion
fpath=(~/.zsh $fpath)
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
autoload -Uz compinit && compinit

Finally, source ~/.zshrc to complete the configuration.

Discussion