您的位置:首页 > 其它

debian下安装git服务器

2018-01-04 18:17 197 查看


① 安装 Git

Linux 做为服务器端系统,Windows 作为客户端系统,分别安装 Git

服务器端:

#yum install -y git


安装完后,查看 Git 版本

[root@localhost ~]# git --version
git version 1.7.1


 

客户端:

下载 Git for Windows,地址:https://git-for-windows.github.io/

安装完之后,可以使用 Git Bash 作为命令行客户端。

安装完之后,查看 Git 版本

$ git --version
git version 2.8.4.windows.1


 


② 服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码

[root@localhost home]# id git
id: git:无此用户
[root@localhost home]# useradd git
[root@localhost home]# passwd git


 


③ 服务器端创建 Git 仓库

设置 /home/data/git/gittest.git 为 Git 仓库

然后把 Git 仓库的 owner 修改为 git

[root@localhost home]# mkdir -p data/git/gittest.git
[root@localhost home]# git init --bare data/git/gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost home]# cd data/git/
[root@localhost git]# chown -R git:git gittest.git/


 


④ 客户端 clone 远程仓库

进入 Git Bash 命令行客户端,创建项目地址(设置在 d:/wamp64/www/gittest_gitbash)并进入:

dee@Lenovo-PC MINGW64 /d
$ cd wamp64/www

dee@Lenovo-PC MINGW64 /d/wamp64/www
$ mkdir gittest_gitbash

dee@Lenovo-PC MINGW64 /d/wamp64/www
$ cd gittest_gitbash

dee@Lenovo-PC MINGW64 /d/wamp64/www/gittest_gitbash
$


 

然后从 Linux Git 服务器上 clone 项目:

$ git clone git@192.168.56.101:/home/data/gittest.git


如果SSH用的不是默认的22端口,则需要使用以下的命令(假设SSH端口号是7700):

$ git clone ssh://git@192.168.56.101:7700/home/data/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:

查看客户端项目目录:



 

项目已经 clone 了。

代码同步(HOOK)

上边git用于做了中心的版本控制

但是还想让服务器接到修改更新后自动同步代码到网站目录中,便于测试开发

如下操作是可以实现
#假定网站目录在/www/web下
cd /home/git/repo.git/hooks
vim post-receive #创建一个钩子
#写入下面内容
GIT_WORK_TREE=/www/web  git checkout -f
#保存退出
chown git:git post-receive
chmod +x post-receive


如此,下次提交修改,代码会自动同步到指定目录中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: