Jenkins安装配置Git -- GitHub --Linux

作者:不是王大锤
链接:https://www.jianshu.com/p/b55674ad5c9f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

一、下载安装

1、下载Git
[root@iZbp1hknxd1d8t804oc6nwZ ~]# wget https://github.com/git/git/archive/v2.8.0.tar.gz
 
 
2、在预安装目录下解压
[root@iZbp1hknxd1d8t804oc6nwZ local]#sudo tar -zxvf v2.8.0.tar.gz 
3、安装git依赖包
[root@iZbp1hknxd1d8t804oc6nwZ local]#sudo yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
4、自定义编译安装git的路径

进入到解压的Git包下执行命令

[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# make prefix=/var/local/git-2.8.0/ all
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# make prefix=/var/local/git-2.8.0/ install
5、配置Git环境变量
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# vi /etc/profile

   在文件中加入:
      GIT_HOME=/var/local/git-2.8.0
      path=$GIT_HOME/bin:$path
6、配置Git
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# git config --global user.name "Username自定义"
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# git config --global user.email "自己github的邮箱"
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# git config --global core.autocrlf false
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# git config --global gui.encoding utf-8
7、配置秘钥
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]#ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
 
 

查看并复制生成的密钥

[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]#cat ~/.ssh/id_rsa.pub
 
 
8、登录GitHub配置秘钥

GitHub:https://github.com/login

 
 

 
 

 
 
9、返回Linux验证是否配置成功
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]# ssh -T git@github.com
 
 

出现这段话代表成功

10、查看Git版本
[root@iZbp1hknxd1d8t804oc6nwZ git-2.8.0]#git --version

二、设置GitHub仓库

登录GitHub:https://github.com/login

 
 
 
 

为Git和GitHub添加远程地址

[root@iZbp1hknxd1d8t804oc6nwZ local]# mkdir gitRepositories  //新建存储GitHub仓库的目录
[root@iZbp1hknxd1d8t804oc6nwZ local]# cd gitRepositories/
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# git init  
初始化空的 Git 版本库于 /var/local/gitRepositories/.git/
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# git remote add origin git@github.com:自己的GitHub名/testAut.git  //添加远程地址,testAut是GitHub前面新建的仓库名,origin是默认的远程仓库名
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# 

查看配置文件

[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# ls -A
.git
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# cd .git/
[root@iZbp1hknxd1d8t804oc6nwZ .git]# vi config  //配置远程地址文件

推送本地仓库内容到远程仓库中

[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# touch 9.txt     //本地仓库中新建文件
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# ls
9.txt  readme.txt
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# git add 9.txt   //将文件添加到status ,可用git status查看
[root@iZbp1hknxd1d8t804oc6nwZ gitRepositories]# git push -u origin master     //从默认分支master推送到远程仓库origin ,master为git默认分支,-u为关联本地master和远程master参数,第一次推送需使用,后续不需要再使用该参数

 

 

推送成功后登录GitHub仓库下可以看到推送的内容
 
 

三、Jenkins配置Git

 
 

暂停,后续更新




posted @ 2022-09-02 16:22  小菜,冲冲冲!  阅读(661)  评论(0编辑  收藏  举报