[root@localhost ~]# yum remove git
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost ~]# yum install gcc perl-ExtUtils-MakeMaker
[root@localhost ~]# cd /src
[root@localhost ~]# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@localhost ~]# tar -zxvf libiconv-1.15.tar.gz
[root@localhost ~]# cd libiconv-1.15
[root@localhost ~]# ./configure --prefix=/usr/local/libiconv && make && make install
[root@localhost ~]# cd /src
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz
[root@localhost ~]# tar -zxvf git-2.10.0.tar.gz
[root@localhost ~]# cd git-2.10.0
[root@localhost ~]# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
[root@localhost ~]# make && make install
[root@localhost ~]# git --version
[root@localhost ~]# useradd -m git
[root@localhost ~]# passwd git
Changing password for user git.
New password:
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# mkdir -p /data/git/test.git
[root@localhost ~]# cd /data/git/test.git
[root@localhost test.git]# git --bare init
Initialized empty Git repository in /home/git/test.git/
[root@localhost test.git]# chown -R git:git /home/git/
[root@localhost test.git]# chmod 755 /home/git/
[root@localhost ~]# vi /etc/passwd
找到 git:x:500:500::/home/git:/bin/bash 这一行
将最后的/bin/bash改为:git-shell的目录 /usr/local/git/bin/git-shell 如下:
git:x:500:500::/home/git://usr/local/git/bin/git-shell
git config --global user.name "你的名字"
git config --global user.email "你的邮箱地址"
chown -R git:git 项目目录
cd 裸仓库目录/hooks 如:
cd /data/git/test.git/hooks
创建脚本
vim post-receive
写入下面脚本代码:
#!/bin/sh
cd 项目目录
unset GIT_DIR
git pull origin master
分配执行权限
chmod +x post-receive
vim /etc/ssh/sshd_config
将下面三行:
# RSAAuthentication yes
# PubkeyAuthentication yes
# AuthorizedKeysFile /root/.ssh/authorized_keys
的注释打开(去掉前面的"#"),如下:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile /root/.ssh/authorized_keys
保存退出,然后重启:service sshd restart
最后设置.ssh目录权限:chmod 700 -R .ssh
本地安装git bash,然后打开
在git bash 里输入下面代码,一路回车即可
ssh-keygen -t rsa -C “你的邮箱地址”
本地生成秘钥后,在C:\Users\你电脑当前用户名\.ssh下可以看到生成的三个文件
在服务端打开 : vim /root/.ssh/authorized_keys
将本地生成的秘钥粘贴上去 ( id_rsa.pub 里的内容)
git clone ssh://[email protected]/xxx/xxx/xxx.git