Update cloned repo from Github
I apologise if any part of this is confusing; it's currently 11:21PM, and I've been trying to get this working since 1PM.
I'm cloning a private Github repository to my working directory using git clone git@github.com:username/repo.git /var/www
. This works perfectly! No troubles.
I have setup a webhook on Github's side to notify my server of any new push events. This webhook is supposed to pull from the Github repo and update any modified files. It is not doing this.
Every time I call the webhook and run the commands I'm about to show you, it responds indicating that it is "up to date" with the "latest version", however it's indicating that the latest version is the version that it was initially cloned with.
I have run through every solution I can find, and there doesn't seem to be anything that works for my particular issue. My PHP webhook presently sports the following (as it's where I gave up):
git reset --hard HEAD
git pull
git status
git submodule sync
git submodule update
git submodule status
This was supposed to be a method to update multiple servers for me at once.. a way to connect everything. At the moment, the only thing that this whole thing is connecting, is my keyboard with my forehead.
Any help is greatly appreciated.
This was an SSH error. For anyone with a similar issue, please ensure that Git is looking for your id_rsa
in the correct place :)
(I'm not entirely certain if I correctly diagnosed the issue you face, so this is a stab in the dark.)
You are using git over ssh to login to github ( git@github.com:username/repo.git
).
If you are doing this from a script which runs from a different user shell (eg webserver user), said script may not have access to your SSH-Agent , thus can't acces your private key and will fail the SSH login.
You will need to tell git how to find the SSH Agent which has your Github private key loaded and unlocked, using the environment variables SSH_AUTH_SOCK
and SSH_AGENT_PID
.
Note: If you want to "update multiple servers at once", meaning you want a server-side git repo mirror, consider using git mirror
instead. This will not waste space for a work-dir checkout and automatically mirror all the remote refs, including (eg) github merge requests; though it will not see/care about the submodules (you'll have to manually create mirrors for them alongside the main repo).
If you want to modify the files and push them back, you'll probably need the workdir(s) of course.
Example Cron script to remote-update local git mirrors over ssh transport; using the keychain tool for ssh agent management.
(You'll have to adapt this concept to fit your php script, obviously.)
$ crontab -e
# m h dom mon dow command
0 23 * * * cd /my/mirrors/ && sh update-mirrors.sh
And the script contents:
$ cat /my/mirrors/update-mirrors.sh
#!/bin/sh
# Git mirrors are created with `git clone --mirror ...`
# to "convert" existing local repo into mirror, use
# $ git clone --mirror --no-hardlinks <local-git-path> <new-mirror.git>
# then update the origin remote to the upstream repo and run
# `git remote update`
# Crontab script needs ssh agent
# This sources a file generated by `keychain' with the following info:
#
#SSH_AUTH_SOCK=/tmp/ssh-TLf5KUaqLQgk/agent.15740; export SSH_AUTH_SOCK;
#SSH_AGENT_PID=15731; export SSH_AGENT_PID;
#
# You may do this some other way
#
. $HOME/.keychain/`/bin/hostname`-sh
d=`pwd`
cd $d
# Now update mirrors (our convention: end dirnames with '.git')
DIRS=`ls -dR *.git`
for f in $DIRS; do
echo "$f"
cd "$d"
if [ -f "$f/HEAD" ]; then
cd "$f"
echo "* updating bare/mirror repo $f ..."
git remote update --prune
elif [ -d "$f/.git" ]; then
cd "$f"
echo "updating clone $f ..."
git remote update
#git pull
fi
done
链接地址: http://www.djcxy.com/p/37822.html
上一篇: JSON密钥是否必须是唯一的?
下一篇: 从Github更新克隆的回购