搭建git服务器

2020-1-6    分类: wordpress教程

环境是centos 6

git笔记

1,先看看防火墙是否禁用端口要么把防火墙关掉

2,安装依赖

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

 

 

3,git下载并安装

https://mirrors.edge.kernel.org/pub/software/scm/git/

cd /usr/local/src
wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz

#解压、编译和安装
tar -zvxf git-2.10.0.tar.gz
cd git-2.10.0
make prefix=/usr/local/git all
make prefix=/usr/local/git install

 

添加环境变量

echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
source /etc/bashrc

 

查看是否安装成功

git --version

 

4,创建git账号并设置密码

useradd -m xgllseo
passwd xgllseo

 

5,创建仓库

mkdir -p /home/git/repositories/test.git
cd /home/git/repositories/test.git
git --bare init
chown -R root:root /home/git/repositories
chmod -R 777 /home/git/repositories/test.git

 

6,用户连接限制

找到git-shell命令所在目录,我的是/usr/local/git/bin

编辑vi /etc/passwd,添加

git:x:500:500::/home/git:/usr/local/git/bin/git-shell

 

7,尝试拉下代码

git init
git remote add origin ssh://git@47.94.209.57:22/home/git/repositories/test.git
git fetch
git branch master origin/master
git checkout master
git pull

 

还有一个问题就是每次git push/pull都要密码。

 

https://www.cnblogs.com/007sx/p/6076151.html