Mac 下 git 命令自动补全

本文介绍如何在Mac上安装并配置Bash与Git补全功能,包括使用Homebrew安装bash-completion,以及下载与Git版本匹配的git-completion.bash文件,最后通过修改~/.bash_profile来启用这些补全功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一. 安装 bash-completion

brew install bash-completion

安装成功后提示:

==> Caveats
Add the following line to your ~/.bash_profile:
  [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

接下来按照提示,将下面语句放到~/.bash_profile

[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

二. 下载 git-completion.bash

访问 https://github.com/git/git
在这里插入图片描述
选择 branch 为你 git 版本的分支,比如我的:

$ git version
git version 2.13.5 (Apple Git-94)

注意: 这里如果不使用相匹配的版本,会导致后面 git 补全命令时报错 Unknown option:

好,选好分支后,找到 contrib/completion/git-completion.bash文件,点击Raw,然后根据地址栏内容进行下载,存为 ~/.git-completion.bash

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

修改 ~/.bash_profile

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

然后执行:

source ~/.bash_profile
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值