git 如何创建一个新的存储库,它是另一个存储库的克隆?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6034904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:29:47  来源:igfitidea点击:

How to create a new repository which is a clone of another repository?

gitgithub

提问by shin

I have a project "MyfirstProject" in github. Now I am making another project "SecondProject" by cloning "MyfirstProject" since core codes will be the same.

我在 github 中有一个项目“MyfirstProject”。现在我通过克隆“MyfirstProject”来制作另一个项目“SecondProject”,因为核心代码将相同。

Whenever I updates in "MYfirstProject" I just pull for updates.

每当我在“MYfirstProject”中更新时,我都会拉取更新。

Now I want to make a repository for this "SecondProject" in github since I have to work in different computers and it will have different codes from "MYfirstProject".

现在我想在 github 中为这个“SecondProject”创建一个存储库,因为我必须在不同的计算机上工作,它会有与“MYfirstProject”不同的代码。

I don't think branching out is right thing to do since I will never merge them.

我不认为分支是正确的做法,因为我永远不会合并它们。

How can I do?

我能怎么做?

Do I need to push to a new repository? Won't it affect pulls from "MyfirstProject"?

我需要推送到新的存储库吗?它不会影响“MyfirstProject”的拉取吗?

What do you do?

你做什么工作?

Thanks in advance.

提前致谢。

回答by Fred Foo

There's probably several ways to do this, including a smarter one, but this is how I would do this:

可能有几种方法可以做到这一点,包括一种更聪明的方法,但我会这样做:

  1. Make a new repo on Github called SecondProject.
  2. Locally clone your MyfirstProject, either from disk or from Github. Then use git pull on the branches you need to move to the second repo.
  3. git remote set-url origin [email protected]:yourname/SecondProject.git
  4. Push it.
  1. 在 Github 上创建一个名为SecondProject.
  2. MyfirstProject从磁盘或 Github 在本地克隆您的. 然后在需要移动到第二个存储库的分支上使用 git pull 。
  3. git remote set-url origin [email protected]:yourname/SecondProject.git
  4. 推它。

Note that the clone retains a shared history with MyfirstProject, which is useful if you change your mind about the "never merge" bit.

请注意,克隆保留了与 的共享历史记录MyfirstProject,如果您改变了“永不合并”位的想法,这将非常有用。

回答by gotgenes

Now I am making another project "SecondProject" by cloning "MyfirstProject" since core codes will be the same.

现在我通过克隆“MyfirstProject”来制作另一个项目“SecondProject”,因为核心代码将相同。

It depends what you mean by "core codes". If it is a library of common data structures, utilities, and such, that should all be contained in a separate git repository, and you should not include application-specific code, which relies on the library, in that repository. The application-specific code should be in a separate, new repository (not cloned from the library repository). Link your application-specific code to the library code the way you would normally link against any third-party library.

这取决于您所说的“核心代码”是什么意思。如果它是一个包含通用数据结构、实用程序等的库,则应将其全部包含在单独的 git 存储库中,并且您不应在该存储库中包含依赖于该库的特定于应用程序的代码。特定于应用程序的代码应该在一个单独的新存储库中(不是从库存储库中克隆的)。将特定于应用程序的代码链接到库代码,就像您通常链接任何第三方库的方式一样。

If instead you mean that you have some application, but you need different configurations depending on which machine you work/compile on, that should be tracked as branches in the same repository, not as a separate clone of git repository. Have a "master" branch which contains the default configuration of your code (e.g., the machine you use most frequently, or the production machine). Configurations specific to your other machines get a separate branch, for example "laptop" branch for your laptop, "work" for your workstation desktop, "cloud" for your Amazon EC2 instance, etc.

相反,如果您的意思是您有一些应用程序,但根据您在哪台机器上工作/编译而需要不同的配置,则应将其作为同一存储库中的分支进行跟踪,而不是作为 git 存储库的单独克隆进行跟踪。有一个“主”分支,其中包含您代码的默认配置(例如,您最常使用的机器或生产机器)。特定于您的其他机器的配置有一个单独的分支,例如您的笔记本电脑的“笔记本电脑”分支,您的工作站桌面的“工作”,您的 Amazon EC2 实例的“云”等。