1、安装 git
sudo apt install git
2、安装 gitk
sudo apt install gitk
3、设置用户名、邮箱和密码
git config --global user.name "名字"
git config --global user.email "邮箱"
4、验证公钥
ssh-keygen -C '邮箱' -t rsa
一路回车,使用命令 cd ~/.ssh进入~/.ssh 文件夹,输入 gedit id_rsa.pub 打开id_rsa.pub文件,复制其中所有内容
5、设置 git 命令自动补全
sudo vim /etc/bash.bashrc
将
#enable bash completion in interactive shells # if ! shopt -oq posix; then # if [ -f /usr/share/bash-completion/bash_completion ]; then # . /usr/share/bash-completion/bash_completion # elif [ -f /etc/bash_completion ]; then # . /etc/bash_completion # fi # fi
去掉注释
#enable bash completion in interactive shells if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi
运行 sudo source /etc/bash.bashrc 生效
6、设置 git 显示分支名称
sudo vim /etc/bash.bashrc
在文末添加
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}[ 33[01;32m]u@h[ 33[00m]:[ 33[01;34m]W$(git_branch)[ 33[00m]$ '
#PS1='${debian_chroot:+($debian_chroot)}[ 33[01;32m]u@h[ 33[00m]:[ 33[01;34m]w[ 33[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}u@h:W$(git_branch)$ '
#PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
fi
git_branch()
{
branch=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
if [ "${branch}" != "" ]
then
if [ "${branch}" = "(no branch)" ]
then
branch="(`git rev-parse --short HEAD`...)"
fi
echo -e " 33[32m[$branch] 33[0m " #颜色设置
fi
}
保存后运行 source /etc/bash.bashrc 生效



