Ubuntu git 设置(一)

本文档详细介绍了如何在Linux系统中安装和配置Git,包括安装git和gitk,设置用户名和邮箱,验证公钥,启用git命令自动补全,以及定制显示分支名称的bash提示符。这些步骤将帮助用户更高效地使用Git进行版本控制。
摘要由CSDN通过智能技术生成

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)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W$(git_branch)\[\033[00m\]\$ '
    #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[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 " \033[32m[$branch]\033[0m "  #颜色设置
   fi
}

保存后运行 source /etc/bash.bashrc 生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

才疏学浅的浅~

谢谢老板,老板大气^_^

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值