使用 Git 将多个项目部署到服务器的最佳方法是什么?
我即将冒险尝试,开始将 Git 用于其他人使用的实际项目!
到目前为止,我已经在一些基本项目上使用了 Git,并在一些大学项目中使用了 Github,但现在我和其他一些人将致力于多个项目。因此,我们将在远程服务器上托管 Git,说实话,如果我们能够开始使用经过尝试和测试的方法来使用 Git 来满足我们的需求,那就太好了。
起初我们想到将 Git master 托管在服务器上,...
站点: /home/vhosts/domain/htdocs
Git: /home/git/domain.git
这听起来像是可行的,但我担心托管一个主网站运行所在的服务器上的存储库,以防它出现故障或丢失数据,因为我们将保留本地副本。我希望将其全部运行在开发服务器上,但有些人认为这太过分了,而且从逻辑上讲这可能是一场噩梦。
公平地说,我们都是应届毕业生,只有业余爱好项目和最后一年的 CS 项目的源代码控制的基本经验,当时流行的选择是颠覆。我们选择 Git 的原因之一是通过其他开发人员的口碑以及在工作中广泛使用它的朋友的推荐。
澄清一下,我们将致力于多个托管项目,并希望使用 Git 进行部署。我们所坚持的是解决这个问题的最佳方法。我们大约有三个人随时在不同的机器上工作,其中有一台实时服务器和(希望)一台开发服务器来测试东西。
对于那些主要处理 Web 应用程序的人来说,如何使用 Git 将工作代码部署到服务器?我们是否为满足我们的需要而找错了树?您可以给 Git 新手一些建议吗?
I am about to take the plunge and start using Git for actual projects that others use!
So far I've used Git on some basic projects and played around with Github for some university projects, but now me and some others will be working on multiple projects. As a result we'll be hosting Git on a remote server and to be honest it'd be great if we could just get started on a tried-and-tested method of using Git for our needs.
At first we thought of hosting the Git master on the server, a la...
Site: /home/vhosts/domain/htdocs
Git: /home/git/domain.git
This sounds like it'd work, but I'm worried about hosting a repository on the server the main website is running from in case it goes down or if we lose data, as we'd be left with our local copies. I'd like to have it all running on a development server, but some think that it is overkill and some thing that logistically it could be a nightmare.
To be fair, we're all recent graduates and have only basic experience with source control on hobby projects and solely on final-year CS projects, with the popular option at that time being subversion. One of the reasons we chose Git was through word-of-mouth from other developers and through recommendations of friends who use it extensively at work.
To clarify, we will be working on multiple, hosted projects and would like to deploy using Git. What we're stuck on is on the best way to handle this. There will be around three of us working on separate machines at any one time with a live server and (hopefully) a development server to test stuff on.
For those who are dealing primarily with web applications, how do you use Git to deploy your working code to the server? Are we barking up the wrong tree for our needs? Any tips you can give a Git novice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要了解的是,所有 Git 存储库本质上都是“本地”的。
当您使用 git clone 克隆存储库时,您将获得整个存储库及其所有更改和日志。如果您丢失了远程存储库,您的本地克隆可以从远程存储库停止的位置继续。
此外,您可以将多个远程存储库附加到本地存储库:例如,当我在站点上工作时,我将拥有自己的本地存储库,并在开发服务器和生产服务器上都有一个远程存储库。然后,只需根据上下文拉动和推送到正确的位置即可。
这些远程存储库没什么特别的:它们只是包含我计算机上相同内容的目录。
因此,您唯一需要担心的事情是确保团队中的每个人都可以访问您的远程存储库:如果您没有任何其他位置可以放置它,则您拥有该站点的服务器就可以了。
The thing you need to understand is that all Git repositories are, essentially, "local".
When you clone a repository using
git clone
, you are getting the entire repository with all of its changes and logs. If you lost the remote repository, your local clone can pick up right where the remote one left off.In addition, you could have multiple remote repositories attached to your local repository: for instance, when I'm working on a site, I'll have my own local repository, and a remote repository on both the development server and the production server. Then, it's just a matter of pulling and pushing to the correct one depending on context.
And those remote repositories are nothing special: they're just directories containing the same things on my computer.
So the only thing you need to worry about is making sure your remote repositories are accessible by every one on your team: if you don't have any other place to put it, the server you have the site on is fine.
我实际上写了一篇 博客文章 关于我用来将我的网站从本地计算机部署到临时服务器,然后部署到实时站点的过程,因为它有点复杂。如果您想使用两层分发架构(登台服务器,然后是实时服务器),那么这篇文章可能对您有用。如果您不想使用临时服务器,您可以将本地计算机配置为直接推送到实时站点,这样更简单。当然,该设置仍然允许您在本地计算机上进行测试。
除此之外,我同意 Mark Trapp 关于 git 去中心化性质的说法。将中央存储库放在 Web 服务器上没有问题,因为您的本地副本包含继续工作并在必要时重建另一个中央存储库所需的所有内容。
I actually wrote a blog post about the procedure I use to deploy my website from a local computer to a staging server and then the live site, since it's somewhat complicated. The writeup might be useful to you if you want to use a two-tier distribution architecture (staging server and then live server). If you don't want to use a staging server, you can configure your local computer to push directly to the live site, and that's way simpler. Of course that setup would still allow you to test on your local computer.
Other than that, I would echo what Mark Trapp said about the decentralized nature of git. There's no problem with putting your central repository on the web server, since your local copy contains everything you need to keep working and to reconstruct another central repository if necessary.
如果您想与一个(或不同的)团队合作,您应该查看 Gitosis:它是一种按用户和项目自定义访问权限(读/写)来管理多个 Git 项目的简单方法。
Gitosis 教程: http: //scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
另一个解决方案是 Gitolite,Gitosis 的进化。
If you want to work with a (or different) team(s), you should look at Gitosis: it is a simple way to manage multiple Git projects with custom access rights (read/write) by user and by project.
A Gitosis tutorial: http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
Another solution is Gitolite, a Gitosis evolution.
我们使用 gitosis 来管理多个用户的多个存储库:
http://fclose.com/b/1432/setting -up-git-server-using-gitosis/
之前我们通过 SSH 连接使用 git。这将使每个人都是管理员。所以我们转向 gitosis。我们可以控制谁可以写入一个存储库以及谁可以读取一个存储库。我们可以有多个管理员。我们还可以设置电子邮件通知方案。我们现在对此很满意。
We use gitosis to manage multiple repositories with multiple users:
http://fclose.com/b/1432/setting-up-git-server-using-gitosis/
Previously we use git through SSH connection. That will make every one is the administrator. So we move to gitosis. We can control who can write to one repository and who can read one repository. And we can have several administrators. We can also set up email notification scheme. We are happy with it by now.