栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Ubuntu git 设置(一)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Ubuntu git 设置(一)

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 生效

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/865409.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号