1. 程式人生 > 實用技巧 >NO.A.0004——Git私有伺服器部署/makefile方式/本地與Git伺服器程式碼交換

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://[email protected]/home/git/repo1       
//使用命令與遠端伺服器建立連線 // 私有git伺服器搭建完成後就可以向連線github一樣連線使用了,
//但是我們的git伺服器並沒有配置金鑰登入,所以每次連線時需要輸入密碼。 //這種形式和剛才使用的形式好像不一樣,前面有ssh://字首,也可以這樣執行 $ git remote add origin [email protected]:repo1
4、本地與遠端伺服器實現程式碼交換: 4.1、推送:把本地版本庫檔案推送到遠端伺服器repo1 版本庫中:
  • 在.git的工作目錄之下——>右鍵——>git同步——>遠端URL:管理——>遠端:private-git——>URL:
    ssh://[email protected]/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://[email protected]/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="">



來自為知筆記(Wiz)