[英]sync local dir with github repo
If I am editing a repository and pushing to a public repository on github, is there a way for another computer to automatically keep a local copy of the most up-to-date version of that repository? 如果我正在编辑存储库并推送到github上的公共存储库,那么另一台计算机是否可以自动保留该存储库最新版本的本地副本?
How can I keep a local folder synced with a github repository? 如何保持本地文件夹与github存储库同步?
You simply need to run git pull
on the local machine. 您只需要在本地计算机上运行
git pull
。 I'd assume you want to do this automatically anytime something changes in the github repository. 我假设您想在github存储库中发生任何更改时自动执行此操作。 In that case, you have two options:
在这种情况下,您有两种选择:
1) Polling - Less ideal (wasteful) - use a Cron job or write a script that simply runs git pull
every minute/hour or whatever timeframe suits your needs. 1) 轮询 - 不太理想(浪费) -使用Cron作业或编写仅在每分钟/小时或任何适合您需要的时间范围内运行
git pull
的脚本。 Here is an example cron job that will pull the repo every minute 这是一个cron作业示例,它将每分钟提取一次回购
* * * * * cd /path/to/your/repo && git pull
2) Webhooks - More ideal but requires running a server and exposing the machine to the public internet - Setup a webhook on github.com that will notify your server via HTTP anytime the remote repository changes and you can pull the changes upon being notified. 2) Webhooks- 更为理想,但需要运行服务器并将计算机公开到公共互联网 -在github.com上设置一个Webhook,该Webhook可以在远程存储库更改时通过HTTP随时通知您的服务器,您可以在收到通知后将更改拉出。 To set up a webhook on github.com go to
要在github.com上设置一个Webhook,请转到
Settings -> Webhooks & Services -> Add WebHook
Github will send an HTTP request to your machine after certain events (commits, branches, etc) occur on the remote repository and you can handle them accordingly. 在远程存储库上发生某些事件(提交,分支等)后,Github会将HTTP请求发送到您的计算机,您可以相应地处理它们。 In your case, probably just by running
git pull
anytime new commits are added to master 在你的情况下,可能只要在新提交提交到master时就运行
git pull
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.