将存储库镜像到另一个存储库中的子文件夹

时间:2020-06-25 19:45:24

标签: git gitlab git-merge git-push

假设我在gitlab中有存储库“ A”。开发人员通常会将代码更改推送到存储库“ A”。 我在同一个gitlab中有另一个存储库'B'。我在存储库'B'中有子文件夹'C'。每当开发人员将更改提交到存储库'A'中时,我都需要在存储库'B中的子文件夹'C'中反映确切的代码更改'。 在gitlab中可以吗?

1 个答案:

答案 0 :(得分:0)

您需要使用git子模块。

  1. 在存储库B的根目录中创建.gitmodules文件
[submodule "Nameofmodule"]
    path = subfolderC
    url = https://gitlab.com/yourrepo (you can also use ssh here)
  1. 初始化您的子模块

git submodule init

  1. 从仓库A中“获取”数据

git submodule update

之后,您将在文件夹C中看到Repo A的内容

我建议您阅读文档https://git-scm.com/book/en/v2/Git-Tools-Submodules

请注意,如果您要使用Gitlab CI,则配置会有所不同

[submodule "project"]
  path = project
  url = ../../group/project.git

原因和说明在这里https://docs.gitlab.com/ee/ci/git_submodules.html