对多个 git 项目使用单个 git 存储库
我很便宜。我不想为很多 github 帐户付费。
我有一个看起来像这样的项目结构。
- /repo 是项目根目录。
- /repo/project1 是我有一个 Java 项目的地方
- /repo/herokurails1 是我有一个 Ruby/Rails 项目的地方,该项目部署到 heroku.com (到一个名为 Heroku 应用程序) hr1-fubar.heroku.com)
- /repo/herokurails2 是我有另一个 Ruby/Rails 项目的地方,它部署到 heroku.com (一个名为 Heroku 应用程序) hr2-fubar.heroku.com)。
所有项目(project1、herokurails1 和 herokurails2 正在积极开发中)。
我希望在某个 git 托管位置(例如 github.com)或什至在办公室的本地 git 服务器上拥有一个存储库。每当 /repo/ 中的任何地方代码发生更改时,我希望能够运行“git push github master”并拥有整个 /repo/树被推送到 github。
但是,我还希望能够将我的 Rails 应用程序部署到 heroku.com,而无需将整个 repo/* 树推送到每个 heroku 应用程序。例如
- /repo/herokurails1> git push heroku master 只会将herokurails1项目部署到heroku,而不会在/repo/*
- /repo/herokurails2>中推送任何其他代码。 git push heroku master 只会将herokurails2项目部署到heroku,也不会推送/repo/*中的任何其他代码。
这可能吗?我需要设置什么特别的东西才能实现这一点吗?或者我是否被多个 git 存储库困住了?
I'm cheap. I don't want to pay for many github accounts.
I have a project structure which looks something like this.
- /repo is the project root.
- /repo/project1 is where I have a Java project
- /repo/herokurails1 is where I have a Ruby/Rails project which deploys to heroku.com (to a heroku app called hr1-fubar.heroku.com)
- /repo/herokurails2 is where I have another Ruby/Rails project which deploys to heroku.com (to a heroku app called hr2-fubar.heroku.com).
All projects (project1, herokurails1, and herokurails2 are under active development).
I would like to have one repository at some git hosting place such as github.com or even a local git server in the office. Whenever code changes anywhere in /repo/, I want to be able to run "git push github master" and have my entire /repo/ tree pushed up to github.
However, I would also like to be able to deploy my rails apps to heroku.com without pushing the entire repo/* tree pushed to each heroku app. e.g.
- /repo/herokurails1> git push heroku master would only deploy the herokurails1 project to heroku without pushing up any other code in /repo/*
- /repo/herokurails2> git push heroku master would only deploy the herokurails2 project to heroku also without pushing up any other code in /repo/*.
Is this possible? Do I need to set up anything special to make this happen? Or am I stuck with multiple git repositories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这很快就会变得非常笨重(特别是 Git 不会让你像 svn 那样推拉子目录)
我会考虑不使用 Github 来存储项目。 Bitbucket 或 CodebaseHQ 有不同的定价模型,这些模型可能更适合您并为您提供所需的简单性。
或者,看看像 Gitosis 这样的东西,它可以通过 Gitlab 等工具变得非常像 Github 风格
This is going to get very unwieldy very quickly (especially as Git won't let you push pull sub directories like svn will)
I would look at not using Github for storing projects. Tools such as Bitbucket or CodebaseHQ have different pricing models which may well fit you better and give you the simplicity you need.
Alternatively, look at something like Gitosis, which can be made to be very Github-esque via tools like Gitlab
您可以在本地使用
git subtree
维护一个从较大的repo
存储库中分离出来的 git 存储库,并从该分离的存储库中进行推送。不过,坦率地说,我要么使用 Adam Dymitruk 建议 或者只是向 GitHub 多付一点钱 - 毕竟他们确实提供了优质的服务......You could use
git subtree
locally to maintain a git repository which is split from your largerrepo
repository, and push from that split repository. Frankly, though, I'd either use one of the free services that Adam Dymitruk suggests or just pay GitHub a bit more - they do provide an excellent service, after all...如果您愿意,如果您不想支付任何费用,可以使用 unfuddle 或 bitbucket。使用子模块在 github 上托管大型文件,例如图像、第 3 方 dll、视频等。这些不会拥有IP。
If you want, you could use unfuddle or bitbucket if you don't want to pay anything. Use submodules to host large files such as images, 3rd party dlls, videos, etc on github. These would hold no IP.
将每个单独的项目放在不同的分支中怎么样?到目前为止,它对我来说效果很好。我有一个 webProjects 的私人仓库,每个分支都以 master 开头,其中有我的 web 项目模板(也可以是空分支),每次我有新项目时,我只是创建一个基于 master 的分支,其中包含项目名称并保持正常工作。
how about putting every separate project in a different branch ? it worked fine with me so far. I have a private repo for webProjects and every branch starts with master which has my web projects template (could be empty branch as well) and every time I have new project I just create a master based branch with the project name and cary on working fine.
这个问题已经没有意义了,因为 GitHub 现在允许用户免费拥有无限的存储库,但无论如何我都会分享我的知识,因为我认为有人会觉得这很有趣。
问题是,您可以拥有一个包含多个项目的存储库,而无需使用 git 子模块创建任何其他存储库。通常,为了使用 git 子模块,您必须为每个子模块创建一个存储库,但我意识到,您可以重用要包含在存储库中的每个项目,而不是为每个项目创建一个单独的存储库。项目,如下所示:
创建将包含 GitHub 上多个项目的存储库。
为了这个答案,假设这个存储库位于 https://github.com/example/example .git
在本地克隆该存储库:
为您想要拥有的每个项目创建一个(最好是孤立的)分支:
在分支 master 中为每个项目添加一个子模块指定正确的分支:
提交并推送:
现在您可以使用此存储库中的每个项目,就好像它们位于自己的存储库中一样。但是,每次创建新分支时,都必须在项目的分支文件夹下创建它。例如,如果您想在project_1中创建一个分支“new_feature”,您必须执行以下命令:
如果您想在其他地方下载项目,您可以:
克隆项目本身而不是其他内容:
如果您想同时使用多个项目,则克隆整个存储库,然后仅下载您实际要使用的项目的内容:
优点:
缺点:
您创建一个名为
project_1/feature
的分支,而不是feature
替代方案:
git subtree
:我知道这个工具是为此特定目的而创建的,但是它有一些缺点,我不知道如何使用它。This question does not make sense anymore since GitHub now allows users to have unlimited repositories for free, but I will share my knowledge anyways because I think someone could find this interesting.
The thing is that you can have a repository with multiple proyects with no need to create any other repository with
git submodule
. Normally, in order to use git submodule you would have to have a repository for each submodule, but I realised that instead of creating a separate repository for each project you want to include in your repository, you can reuse the repository you want to include your projects in, like this:Create your repository which will contain multiple projects on GitHub.
For the sake of this answer, let's say this repository is at https://github.com/example/example.git
Clone that repository locally:
Create a (preferably orphan) branch for each of the projects you want to have:
Add in branch master a submodule for each of the projects specifying the correct branches:
Commit and push:
Now you can use each project in this repository as if they were each in it's own repository. However, each time you create a new branch you must create it under the project's branch folder. For instance, if you want to create a branch 'new_feature' in project_1 you must execute this:
And if you want to download a project anywhere else, you can either:
Clone the project itself and nothing else:
Or clone the whole repository if you want to work with multiple projects at the same time, and then download only the contents of the projects you are actually going to work with:
Advantages:
Disadvantages:
Instead of
feature
you create a branch calledproject_1/feature
Alternatives:
git subtree
: I have understood this tool is created for this specific purpose, but it has some disadvantages and I don't know how to use it.