创建服务器端代码托管仓库(远程连接仓库)
给服务器创建git用户
adduser git
# 给git用户添加密码
passwd git
添加要登录用户的公钥
mkdir /home/git
mkdir .ssh
touch authorized_keys
#使用vim将公钥添加到authorized_keys文件中,一行一个
Ubuntu公钥生成:http://blog.csdn.net/mrgong_/article/details/78693283
Windows公钥:C:\Users\用户名.ssh
选定目录作为服务器端代码托管文件夹(裸仓库)
mkdir /opt/code
cd /opt/code
git init --bare gongsc.git
添加钩子文件
1、创建post-receive
cd /opt/code/gongsc.git
touch post-receive
2、使用vim打开post-receive将如下shell写入文件中
#!/bin/bash
IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi
unset GIT_DIR
DeployPath="/var/www/gongsc"#这里写项目实际部署的目录
cd $DeployPath
git fetch --all
git reset --hard origin/master
3、修改post-receive文件权限
chmod +x post-receive
服务器端创建部署项目的文件夹
这个目录是实际运行的线上代码
cd /var/www/
git clone /opt/code/gongsc.git
Git客户端设置
将远程仓库进行克隆
git clone git@IP:/opt/code/gongsc.git
创建测试文件,上传到远程仓库
#进入gongsc目录创建一个测试文件index.html
git add .
git commit -m 'create new file'
git push
转:http:/ /www.imooc.com/article/17874?block_id=tuijian_wz
来源:CSDN
作者:MrGong_
链接:https://blog.csdn.net/MrGong_/article/details/78693987