安装Git
Git支持全平台,包括Windows、Linux、macOS系统,下面我们以三个平台为例,介绍如何安装Git:
1. Windows
下载安装包,双击安装即可,地址为: https://git-scm.com/download/win
2. Ubuntu Linux
1
|
sudo apt install -y git
|
sudo apt install -y git
3. macOS
自动补全
git提供了大量子命令和参数,相信没有一个人能够记全所有参数,也没有这个必要。在命令行环境下,git可以通过自动补全的方式,来提升命令和参数的输入效率,减轻使用者的记忆成本,因此,我们下面就讲解一下在命令行环境下,如何开启git自动补全。
在git的源码库上有对应的脚本,可以根据自己当前使用的git版本(git version
),下载对应的脚本,这里以下小编当前用的v2.42.0
版本为例:
- zsh:
1
2
3
|
wget https://raw.githubusercontent.com/git/git/v2.42.0/contrib/completion/git-completion.zsh -O $HOME/.git-completion.zsh
echo 'source $HOME/.git-completion.zsh' >> $HOME/.zshrc
source $HOME/.git-completion.zsh
|
wget https://raw.githubusercontent.com/git/git/v2.42.0/contrib/completion/git-completion.zsh -O $HOME/.git-completion.zsh
echo 'source $HOME/.git-completion.zsh' >> $HOME/.zshrc
source $HOME/.git-completion.zsh
- bash:
1
2
3
|
wget https://raw.githubusercontent.com/git/git/v2.42.0/contrib/completion/git-completion.bash -O $HOME/.git-completion.bash
echo 'source $HOME/.git-completion.bash' >> $HOME/.bashrc
source $HOME/.git-completion.bash
|
wget https://raw.githubusercontent.com/git/git/v2.42.0/contrib/completion/git-completion.bash -O $HOME/.git-completion.bash
echo 'source $HOME/.git-completion.bash' >> $HOME/.bashrc
source $HOME/.git-completion.bash
根据自己的版本号,替换掉上面URL中的v2.42.0
即可。
之后就可以输入git命令测试一下啦。