如何设置自动更新 Git
How To Set Up Auto Updating Git
我正在使用 Github 来存储我的项目,想知道是否有办法让我的存储库实时自动更新。
为了澄清我的意思,我目前正在使用旧的 "git clone" "git add" "git commit" "git push" 技术,但它变得相当乏味。
我可以采用什么机制来实现这一目标?
在推送端,您可以使用本地 .git/hooks/post-commit
,其中包括:
#!/bin/sh
git push origin master
(假设您从 master
推送:您在“How to automatically push after committing in git?”有其他选项)
如果您希望本地仓库始终与远程 GitHub 仓库保持同步,您可以设置一个 webhook 来监听推送事件并自动为您拉取。
例如见this webhook (or this one):
<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ($_SERVER['HTTP_X_GITHUB_EVENT'] == 'push') {
shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull' );
}
?>hi
OP NodziGames decided 寻求更 "on demand" 的方法:
create a Makefile where I can clone, add new files, commit and push via a single command.
我正在使用 Github 来存储我的项目,想知道是否有办法让我的存储库实时自动更新。
为了澄清我的意思,我目前正在使用旧的 "git clone" "git add" "git commit" "git push" 技术,但它变得相当乏味。
我可以采用什么机制来实现这一目标?
在推送端,您可以使用本地 .git/hooks/post-commit
,其中包括:
#!/bin/sh
git push origin master
(假设您从 master
推送:您在“How to automatically push after committing in git?”有其他选项)
如果您希望本地仓库始终与远程 GitHub 仓库保持同步,您可以设置一个 webhook 来监听推送事件并自动为您拉取。
例如见this webhook (or this one):
<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ($_SERVER['HTTP_X_GITHUB_EVENT'] == 'push') {
shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull' );
}
?>hi
OP NodziGames decided
create a Makefile where I can clone, add new files, commit and push via a single command.