zoukankan      html  css  js  c++  java
  • Git 服务器搭建

    这里我们来搭建一个 git 服务端作为日常的使用,为什么要搭建服务端:

    (1) Git 是一个分布式的开源版本控制系统,也就是说,每台客户端都可以充当控制中心,我从本机拉取代码,再提交代码到本机,不需要依赖网络,各自开发各自的
    (2) Git 也可以设置一个服务端,用来合并多台客户端的最终版本代码,平时的小改动由我们自己电脑里面的控制中心来管理,服务端不用关心
    (3) GitHub 是公开的,我们可以拿来作为 git 服务端,但是 GitHub 的私有仓库是要花钱买的,所以我们可以想办法搭建一个私有的,只供自己公司使用的服务端
    (4) GitLab 也是公开的,且私有仓库也是免费的,跟 GitHub 一样是 web 界面的 git 服务端,后续我们会使用 GitLab 作为服务端,但这里先搭建一个使用命令行操作的服务端

    服务端配置:

    [root@localhost ~]$ yum install -y git              # 安装git
    [root@localhost ~]$ useradd -s /sbin/nologin git    # 创建git用户
    [root@localhost ~]$ mkdir /home/git/.ssh            # 创建.ssh目录,用来存放客户端的公钥,客户端通过密钥的方式与服务端进行通信
    [root@localhost ~]$ touch /home/git/.ssh/authorized_keys
    [root@localhost ~]$ chown -R git:git /home/git/.ssh/ 
    [root@localhost ~]$ chmod 600 /home/git/.ssh/authorized_keys
    [root@localhost ~]$ mkdir -p /data/git              
    [root@localhost ~]$ cd /data/git                    # 我们使用/data/git目录来存放多个git仓库
    [root@localhost git]$ git init --bare sample.git    # 创建一个裸仓库,仓库目录为sample.git,可以自行定义git仓库名,但一般以.git结尾
    [root@localhost git]$ chown -R git.git sample.git

    客户端如何拉取/上传代码到服务端:

    (1) 首先要先把客户端的公钥放到服务端的 /home/git/.ssh/authorized_keys 文件里,实现客户端与服务端互相通信
    (2) 客户端拉取远程服务端的仓库:git clone git@server_ip:/data/git/sample.git
    (3) 最后就可以修改并上传代码到服务端仓库了:git add ...  git commit ... git push

        

  • 相关阅读:
    HDU 4632 CF 245H 区间DP(回文)
    Cloud Foundry中 JasperReports service集成
    Graphs and Minimum Cuts(Karger's Min-Cut Algorithm)
    【大盛】HTC one/M7 ROM 最新本地化OrDroid8.2.6 高级、快速设置 永久root 更多自定义 稳定 流畅
    Android开发工具GenyMotion安装和使用方法
    CF 121E Lucky Array 【树状数组】
    [每日一题] OCP1z0-047 :2013-08-02 权限―――分配系统权限
    iOS 应用程序本地化
    Storm系列(十五)架构分析之Executor-Spout
    Ganglia系列(一)安装
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10294362.html
Copyright © 2011-2022 走看看