1、在宝塔里安装 WebHook,然后生成hook密钥

配置文件

11#!/bin/bash
echo ""
#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#判断宝塔WebHook参数是否存在
if [ ! -n "$1" ];
then
echo "param参数错误"
echo "End"
exit
fi
#git项目路径
gitPath="/www/wwwroot/$1"
#git 网址
gitHttp="http://github.com/fengqiangjun/$1.git"

echo "Web站点路径:$gitPath"

#判断项目路径是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
#判断是否存在git目录
if [ ! -d ".git" ]; then
echo "在该目录下克隆 git"
git clone $gitHttp gittemp
mv gittemp/.git .
rm -rf gittemp
fi
#拉取最新的项目文件
git reset --hard origin/master
git pull
#设置目录权限
chown -R www:www $gitPath
echo "End"
exit
else
echo "该项目路径不存在"
echo "End"
exit
fi

2、在github后台设置webHook密钥和链接

3、git pull

cr ~
git config --global user.name "用户名"
git config --global user.email "邮箱"
git config --global credential.helper store

//会生成.gitconfig 的文件,查看
cat .gitconfig //报错cat: .gitconfig : No such file or directory
cat ~/.gitconfig //显示内容

[user]
name = 输入的用户名
email = 输入的邮箱
[credential]
helper = store

//第一次pull会提示输入用户名密码
[root@iZ25mi9h7ayZ test]# git pull
Username for 'https://gitee.com': xxxx@xxxx.com
Password for 'https://xxxx@xxxx.com@gitee.com':输入正确密码(看不到输入内容)
//生成.git-credentials 隐藏文件
cat ~/.git-credentials
https://Username:Password@gitee.com

vi ~/.git-credentials

4、修改“.git”文件夹里面的“config”文件

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

ignorecase = true

precomposeunicode = false

[remote "origin"]

url = https://github.com/checkfrank/checkfrank.github.io.git

fetch = +refs/heads/*:refs/remotes/origin/*

pushurl = https://github.com/checkfrank/checkfrank.github.io.git

[branch "master"]

remote = origin

merge = refs/heads/master

4、生成公钥
ssh-keygen