NO.A.0004——Git私有服务器部署/makefile方式/本地与Git服务器代码交换

一、在linux服务器上搭建私有Git服务程序:make编译方式

    远程仓库实际上和本地仓库没啥不同,纯粹为了7x24小时开机并交换大家的修改。GitHub就是一个免费托管开源代码的远程仓库。但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用。

 
1、环境准备:
        Linux主机:centos7.6-1810
        Git版本:git-2.5
2、安装Git服务器:
1、环境准备:
[root@localhost ~]# yum -y install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel 
>gcc gcc-c++ autoconf perl-ExtUtils-MakeMaker package Installed: expat-devel.x86_64 0:2.1.0-12.el7 gcc.x86_64 0:4.8.5-44.el7
 gcc-c++.x86_64 0:4.8.5-44.el7 gettext-devel.x86_64 0:0.19.8.1-3.el7
libcurl-devel.x86_64 0:7.29.0-59.el7_9.1 openssl-devel.x86_64 1:1.0.2k-19.el7 zlib-devel.x86_64 0:1.2.7-18.el7 Dependency Installed: cpp.x86_64 0:4.8.5-44.el7 gettext-common-devel.noarch 0:0.19.8.1-3.el7
git.x86_64 0:1.8.3.1-23.el7_8 glibc-devel.x86_64 0:2.17-317.el7
glibc-headers.x86_64 0:2.17-317.el7 kernel-headers.x86_64 0:3.10.0-1160.6.1.el7
keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-50.el7
libcom_err-devel.x86_64 0:1.42.9-19.el7 libkadm5.x86_64 0:1.15.1-50.el7
libmpc.x86_64 0:1.0.1-3.el7 libselinux-devel.x86_64 0:2.5-15.el7 libsepol-devel.x86_64 0:2.5-10.el7 libstdc++-devel.x86_64 0:4.8.5-44.el7
libverto-devel.x86_64 0:0.2.5-4.el7 mpfr.x86_64 0:3.1.1-4.el7
pcre-devel.x86_64 0:8.32-17.el7 perl-Error.noarch 1:0.17020-2.el7
perl-Git.noarch 0:1.8.3.1-23.el7_8 perl-TermReadKey.x86_64 0:2.30-20.el7 Updated: cpio.x86_64 0:2.11-28.el7 curl.x86_64 0:7.29.0-59.el7_9.1
perl.x86_64 4:5.16.3-297.el7 Dependency Updated: e2fsprogs.x86_64 0:1.42.9-19.el7 e2fsprogs-libs.x86_64 0:1.42.9-19.el7 expat.x86_64 0:2.1.0-12.el7
glibc.x86_64 0:2.17-317.el7 glibc-common.x86_64 0:2.17-317.el7 krb5-libs.x86_64 0:1.15.1-50.el7
libcom_err.x86_64 0:1.42.9-19.el7 libcurl.x86_64 0:7.29.0-59.el7_9.1
libgcc.x86_64 0:4.8.5-44.el7 libgomp.x86_64 0:4.8.5-44.el7 libss.x86_64 0:1.42.9-19.el7
libstdc++.x86_64 0:4.8.5-44.el7 perl-libs.x86_64 4:5.16.3-297.el7 Complete! //2、下载Git-2.5.0版本并解压tar包生成makefire: [root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.5.0.tar.gz [root@localhost ~]# tar -zxvf git-2.5.0.tar.gz [root@localhost git-2.5.0]# autoconf [root@localhost git-2.5.0]# ./configure prefix=/usr/local/git/ //生成makefile //3、make && make install [root@localhost git-2.5.0]# make GEN bin-wrappers/test-wildmatch GEN git-remote-testgit [root@localhost git-2.5.0]# make install hatchanged; do \ rm -f "$execdir/$p" && \ test -z "" && \ ln "$execdir/git" "$execdir/$p" 2>/dev/null || \ ln -s "git" "$execdir/$p" 2>/dev/null || \ cp "$execdir/git" "$execdir/$p" || exit; \ done && \ remote_curl_aliases="git-remote-https git-remote-ftp git-remote-ftps" && \ for p in $remote_curl_aliases; do \ rm -f "$execdir/$p" && \ test -z "" && \ ln "$execdir/git-remote-http" "$execdir/$p" 2>/dev/null || \ ln -s "git-remote-http" "$execdir/$p" 2>/dev/null || \ cp "$execdir/git-remote-http" "$execdir/$p" || exit; \ done && \ ./check_bindir "z$bindir" "z$execdir" "$bindir/git-add" //4、配置生效文件及软连接: [root@localhost git-2.5.0]# vim /etc/profile //将git指令添加到bash中 export PATH=$PATH:/usr/local/git/bin //在profile中添加该内容 [root@localhost git-2.5.0]# source /etc/profile //使配置文件生效 [root@localhost ~]# ln -s /usr/local/git/bin/git /usr/bin/ //创建软连接 [root@localhost git-2.5.0]# git -version git version 2.5.0 //5、添加用户 [root@localhost ~]# adduser -r -c 'git version control' -d /home/git -m git
                          //此命令执行后会创建/home/git目录作为git用户的主目录。 [root@localhost ~]# passwd git //为git用户创建密码 [root@localhost ~]# su git //切换到git用户之下 //6、创建repo1仓库 [git@localhost ~]$ git --bare init /home/git/repo1 Initialized empty Git repository in /home/git/repo1/ //创建git仓库repo1.并初始化仓库。推荐使用git --bare init //如果不使用“--bare”参数,初始化仓库后,提交master分支时报错。 //这是由于git默认拒绝了push操作,需要.git/config添加如下代码: [receive] denyCurrentBranch = ignore [git@localhost ~]$ ls repo1 //查看服务器上的远程仓库创建完成。
3、把本地仓库推送到服务器上
//在本地电脑:右键——>Git Bash Here
$ git remote add origin ssh://git@192.168.1.60/home/git/repo1       
//使用命令与远程服务器建立连接 // 私有git服务器搭建完成后就可以向连接github一样连接使用了,
//但是我们的git服务器并没有配置密钥登录,所以每次连接时需要输入密码。 //这种形式和刚才使用的形式好像不一样,前面有ssh://前缀,也可以这样执行 $ git remote add origin git@192.168.1.60:repo1
 
4、本地与远程服务器实现代码交换:
4.1、推送:把本地版本库文件推送到远程服务器repo1 版本库中:
  • 在.git的工作目录之下——>右键——>git同步——>远端URL:管理——>远端:private-git——>URL: ssh://git@192.168.1.60/home/git/repo1——>保存——>推送:服务器用户名:密码——>推送完成——>在Git服务器远程仓库就可查看到仓库文件——>END
在Git服务端查看推送的数据
[git@localhost ~]$ ls repo1/
branches  config  description  HEAD  hooks  info  objects  refs
 
4.2、拉取:从远程服务器git版本库中下载源码文件
在clone-repos目录下:
  • 右键——>Git 克隆——>URL: ssh://git@192.168.1.60/home/git/repo1——>目录:E:\NO.2——GitHub Repository\Repository\clone-repos\repo1——>用户名:密码——>克隆完成——END
 
 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

<wiz_marker id="wiz-painter-root" style="">

 





posted on 2020-11-23 18:00  yanqi_vip  阅读(153)  评论(0)    收藏  举报

导航