|NO.Z.00008|——————————|^^ 部署 ^^|——|Git&Git私有服务器部署.V01|——|Git.Server部署&Linux|

一、在linux服务器上搭建私有Git服务程序:
### --- 在linux服务器上搭建私有Git服务程序:

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

~~~     Linux主机:centos7.6-1810
~~~     Git版本:git-2.5

一、安装Git服务器:
### --- 环境准备:

[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
### --- 下载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 
~~~     生成makefile

[root@localhost git-2.5.0]# autoconf        
[root@localhost git-2.5.0]# ./configure prefix=/usr/local/git/      
### --- 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"
### --- 配置生效文件及软连接:

[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
### --- 添加用户:此命令执行后会创建/home/git目录作为git用户的主目录。

[root@localhost ~]# adduser -r -c 'git version control' -d /home/git -m git     
[root@localhost ~]# passwd git                          // 为git用户创建密码
[root@localhost ~]# su git                              // 切换到git用户之下
### --- 创建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                                                   // 查看服务器上的远程仓库创建完成。
二、、把本地仓库推送到服务器上
### --- 在本地电脑:右键——>Git Bash Here
~~~     使用命令与远程服务器建立连接
~~~     私有git服务器搭建完成后就可以向连接github一样连接使用了,
~~~     但是我们的git服务器并没有配置密钥登录,所以每次连接时需要输入密码。
~~~     这种形式和刚才使用的形式好像不一样,前面有ssh:

$ git remote add origin ssh://git@192.168.1.60/home/git/repo1       
~~~     # 前缀,也可以这样执行

$ git remote add origin git@192.168.1.60:repo1

三、本地与远程服务器实现代码交换:
### --- 推送:

~~~     把本地版本库文件推送到远程服务器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
### --- 拉取:

~~~     从远程服务器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

 

 

posted on   yanqi_vip  阅读(22)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示