一、安装

  1. sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel sudo yum install gcc perl-ExtUtils-MakeMaker

  2. 安装 sudo wget https://github.com/git/git/archive/v2.9.2.tar.gz sudo tar -zvxf v2.9.2.tar.gz cd git-2.9.2 sudo make prefix=/usr/local/git all sudo make prefix=/usr/local/git install

  3. 将git设置为默认路径,不然后面克隆时会报错 sudo ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack sudo ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack

  4. 添加git用户和用户组用来运行git服务

    sudo groupadd git
    sudo useradd git -g git
    sudo passwd git
    su - git
    

    二、创建证书登录

  5. cd /home/git
    mkdir .ssh
    chmod 700 .ssh
    touch .ssh/authorized_keys
    chmod 600 .ssh/authorized_keys
    将公钥导入到authorized_keys
    
  6. 初始化Git仓库

    cd /data
    mkdir gitrepo
    chown git:git gitrepo/
    cd gitrepo
    git init --bare starins.git
    chown -R git:git starins.git
    

    三、使用

    git clone ssh://git@ip:port/data/gitrepo/starins.git