![04e316fac59771272a24669c430b6463.png](https://img-blog.csdnimg.cn/img_convert/04e316fac59771272a24669c430b6463.png)
1 - git安装及版本
Centos7.2默认自带的git版本是 1.8.3。高级功能中的worktree并不支持。
首先升级git版本。
yum install git
显然是不行的。因为系统repo内并没有git的新版本。因此需要使用包含有最新版本git的仓库。
How to install latest version of git on CentOS 7.x/6.xstackoverflow.com![fef0a70adef381a66c688c65ec4453fb.png](https://img-blog.csdnimg.cn/img_convert/fef0a70adef381a66c688c65ec4453fb.png)
You can use WANDisco's CentOS repository to install Git 2.x: for CentOS 6, for CentOS 7
Install WANDisco repo package:
yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm
- or -
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm
- or -
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
Install the latest version of Git 2.x:
yum install git
git --version
As of 16 Jul. 2019, the latest available version from WANDisco is 2.22.0.
2 - 创建git用户并为其分配权限
groupadd git
useradd git -g git
passwd git // 为git设置密码。方便部署,使用账户密码访问仓库
vim /etc/passwd
// 修改其bash为 git-shells 禁止使用ssh远程登录服务器
![a8ff96133b878be98d9194bf4c92597f.png](https://img-blog.csdnimg.cn/img_convert/a8ff96133b878be98d9194bf4c92597f.png)
经过上述步骤,准备好了所需要的一切配置。
3 - 创建裸仓库并提交代码
cd /home/git
mkdir -pv example.git
cd example.git
git init --bare
本地使用git-bash将仓库clone下来并操作。
git clone ssh://git@domain:[port]/home/git/example.git
如果连接正常,会提示输入git密码。就可以顺利clone远程服务器的仓库到本地。这是一个裸仓库,什么内容都没有。修改之后:
git add --all
git commit -m "test push code to remote server"
git push origin master
以上就是全部内容,happy codding~~