在网站上使用git source control [英] Using git source control with a website

查看:52
本文介绍了在网站上使用git source control的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我只想在服务器上设置Git,但是我遇到了上百万个问题,所以请不要理会.

我可以设置一个普通的git repo,然后让我的Web服务器与git repo同步(自动读取)吗?

我只是一个2人小组的成员,并且比其他任何版本控制都更喜欢使用Git.

解决方案

TL; DR

您可以从Web服务器中 pull ,但是 push 到非裸露的存储库需要许多额外的步骤,并且可能会造成问题.正确的做法通常是使用Webhook或部署工具来触发对Git存储库的提交,但是还有一些更简单的选项,例如服务器端cron作业.

使用Cron作业

要获得所需功能的方法是使用cron作业.举一个简单的例子,您可以每分钟轮询git存储库并提取更改,例如:

  * * * * * cd/path/to/www&&git pull 

如果您需要重新启动Web服务以利用修改后的资源,那么显然您也需要这样做.

使用挂钩和集成

如果您使用的是GitHub或其他托管的存储库服务,则通常可以利用与AWS或Heroku等提供程序的集成.特别是,Heroku很不错,因为每次推送到master分支都将重新编译并重新部署您的Web服务,而无需执行其他操作.

有关更多信息,请参见以下内容:

使用完整部署工具

如果您有更复杂的要求,则可能需要功能更强大的部署工具.一个示例是 Capistrano ,它通常用于Ruby on Rails项目,但也可以用于管理其他类型的部署应用程序和框架.当然,一些研究会发现您可能会更喜欢的其他部署工具,但这是一个合理的起点.

So I just want to set up Git on my server, but I'm running into a million problems so forget that.

Can I set up a normal git repo and then have my web server "auto" sync (just read, I guess) with the git repo?

I'm just part of a 2 person team and would prefer to use Git over any other version control.

解决方案

TL;DR

You can pull from your web server, but pushing to a non-bare repository requires a number of extra steps and can create problems. The right thing to do is usually to use a webhook or deployment tool that triggers on commits to a Git repository, but there are simpler options such as server-side cron jobs.

Use a Cron Job

On way to get the functionality you want is with a cron job. As a simplistic example, you could poll your git repository every minute and pull changes, e.g.:

* * * * * cd /path/to/www && git pull

If you have a web service that needs to be restarted to take advantage of modified resources, then you'd obviously need to do that too.

Use Hooks and Integrations

If you're using GitHub or other hosted repository service, you can often take advantage of integrations with providers like AWS or Heroku. In particular, Heroku is nice because each push to the master branch will recompile and redeploy your web service without requiring additional action.

For more information, see the following:

Use a Full-Fledged Deployment Tool

If you have more complex requirements, you probably need a more capable deployment tool. One example is Capistrano, which is often used for Ruby on Rails projects but can also be used to manage deployments for other types of applications and frameworks. Some research will certainly turn up other deployment tools that you may like better, but it's a reasonable place to start.

这篇关于在网站上使用git source control的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆