Git服务器搭建
参考文献:https://www.cnblogs.com/dee0912/p/5815267.html
https://blog.csdn.net/wave_1102/article/details/47779401
环境:CentOS7
① 安装 Git
1、安装依赖的包
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
2、下载git源码并解压缩
$ wget https://github.com/git/git/archive/v2.17.0.tar.gz
$ tar -xzvf v2.17.0.tar.gz
$ cd git-2.17.0/
3、编译安装
将其安装在“/usr/local/git”目录下。
$ make prefix=/usr/local/git all
$ sudo make prefix=/usr/local/git install
4、此时你如果使用git --version 查看git版本的话,发现(-bash: git: command not found)
方法一:
你安装到/usr/local可以是因为/usr/local/bin这个目录默认已经加入了PATH环境变量中,这样你的git会安装到/usr/local/bin这个目录,所以你在shell下执行时可以找到这个命令。
这是因为安装到/usr/local/git下面没有添加path,只需要手动将/usr/local/git/bin目录加入PATH环境变量就可以了:
export PATH=$PATH:/usr/local/git/bin
方法二:
$ vi /etc/profile
添加以下语句
export PATH=$PATH:/usr/local/git/bin
然后保存退出,执行下面语句使修改文件立马生效
source /etc/profile
5、
② 服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码
[root@localhost home]# id git
id: git:无此用户
[root@localhost home]# useradd git
[root@localhost home]# passwd git
③ 服务器端创建 Git 仓库
设置 /home/git/data/gittest.git 为 Git 仓库
然后把 Git 仓库的 owner 修改为 git
[root@localhost /]# cd /home/data/
[root@localhost data]# mkdir git
[root@localhost data]# cd git/
[root@localhost git]# mkdir -p gittest.git
[root@localhost git]# git init --bare gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost git]# chown -R git:git gittest.git/
④ 客户端 clone 远程仓库
进入 Git Bash 命令行客户端,创建项目地址并进入:
然后从 Linux Git 服务器上 clone 项目:
$ git clone git@192.168.10.43:/home/data/git/gittest.git
如果SSH用的不是默认的22端口,则需要使用以下的命令(假设SSH端口号是7700):
$ git clone git@192.168.10.43:7700/home/data/git/gittest.git
当第一次连接到目标 Git 服务器时会得到一个提示:
The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/SCA059EqoUOzbFoZdfmMh3B259nigfmvdadqQ.
Are you sure you want to continue connecting (yes/no)?
选择 yes:
Warning: Permanently added '192.168.56.101' (RSA) to the list of known hosts.
此时 C:\Users\用户名\.ssh 下会多出一个文件 known_hosts,以后在这台电脑上再次连接目标 Git 服务器时不会再提示上面的语句。
错误解决:在clone的时候碰到这个问题:

什么原因呢?原来代码服务器【192.168.57.61】上的git安装路径是/usr/local/git,不是默认路径,根据提示,在git服务器192.168.57.61上, 建立链接文件:
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
添加软连接之后再执行clone一下,就ok了。
⑤ 客户端创建 SSH 公钥和私钥

浙公网安备 33010602011771号