Linux搭建git服务器教程并自动同步到web根目录
一、安装 GitLinux 做为服务器端系统,Windows 或MAC作为客户端系统,分别安装
Git服务器端:#yum install -y git安装完后,
查看 Git 版本[root@localhost ~]# git --versiongit version 1.7.1
客户端:下载 Git for Windows,
地址:https://git-for-windows.github.io/安装完之后,可以使用 Git Bash 作为命令行客户端。
安装完之后,查看 Git 版本$ git --versiongit version 2.8.4.windows.1
二、服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码
[root@localhost home]# id gitid: 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.gitInitialized 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/wwwdee@Lenovo-PC MINGW64 /d/wamp64/www
$ mkdir gittest_gitbashdee@Lenovo-PC MINGW64 /d/wamp64/www
$ cd gittest_gitbashdee@Lenovo-PC MINGW64 /d/wamp64/www/gittest_gitbash
$然后从 Linux Git 服务器上 clone 项目:
$ git clone git@192.168.56.101:/home/data/gittest.git
项目已经 clone 了。也可以使用 tortoiseGit 客户端来管理项目:
服务端已经配置好了。如果上传文件后要自动同步到web根目录下面可以这样操作:
[root@localhost]$ cd /home/workspace/wwwroot.git/hooks
[root@localhost]$ cat > post-receive <<EOF>#!/bin/bash>git --work-tree=/home/website/wwwroot checkout -f>EOF
[root@localhost]$ chmod +x post-receive
浙公网安备 33010602011771号